add explodable script
This commit is contained in:
@@ -4926,6 +4926,100 @@ ParticleSystemRenderer:
|
|||||||
m_MeshWeighting1: 1
|
m_MeshWeighting1: 1
|
||||||
m_MeshWeighting2: 1
|
m_MeshWeighting2: 1
|
||||||
m_MeshWeighting3: 1
|
m_MeshWeighting3: 1
|
||||||
|
--- !u!1 &6363008927783646894
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 3726223533882090415}
|
||||||
|
- component: {fileID: 3526635589839092049}
|
||||||
|
- component: {fileID: 7545598716694529264}
|
||||||
|
- component: {fileID: 7668621773188834713}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: ExplodeRadius
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 0
|
||||||
|
--- !u!4 &3726223533882090415
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6363008927783646894}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 18.43488, y: 18.43488, z: 18.43488}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 6754763150105653226}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!135 &3526635589839092049
|
||||||
|
SphereCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6363008927783646894}
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_LayerOverridePriority: 0
|
||||||
|
m_IsTrigger: 1
|
||||||
|
m_ProvidesContacts: 0
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 3
|
||||||
|
m_Radius: 0.5
|
||||||
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &7545598716694529264
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6363008927783646894}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: fcf160d0f430fff438a4e57b70f778b2, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::Explosion
|
||||||
|
--- !u!54 &7668621773188834713
|
||||||
|
Rigidbody:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6363008927783646894}
|
||||||
|
serializedVersion: 5
|
||||||
|
m_Mass: 1
|
||||||
|
m_LinearDamping: 0
|
||||||
|
m_AngularDamping: 0.05
|
||||||
|
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||||
|
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||||
|
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ImplicitCom: 1
|
||||||
|
m_ImplicitTensor: 1
|
||||||
|
m_UseGravity: 0
|
||||||
|
m_IsKinematic: 0
|
||||||
|
m_Interpolate: 0
|
||||||
|
m_Constraints: 0
|
||||||
|
m_CollisionDetection: 0
|
||||||
--- !u!1 &7529463216777598777
|
--- !u!1 &7529463216777598777
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -4964,6 +5058,7 @@ Transform:
|
|||||||
- {fileID: 2953567605728542920}
|
- {fileID: 2953567605728542920}
|
||||||
- {fileID: 6184526720724378978}
|
- {fileID: 6184526720724378978}
|
||||||
- {fileID: 4002096401500763546}
|
- {fileID: 4002096401500763546}
|
||||||
|
- {fileID: 3726223533882090415}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!33 &8008322410806594511
|
--- !u!33 &8008322410806594511
|
||||||
@@ -5087,6 +5182,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier: Assembly-CSharp::Tnt
|
m_EditorClassIdentifier: Assembly-CSharp::Tnt
|
||||||
explodeLight: {fileID: 5338768621936571555}
|
explodeLight: {fileID: 5338768621936571555}
|
||||||
explodeParticle: {fileID: 5366483297162523608}
|
explodeParticle: {fileID: 5366483297162523608}
|
||||||
|
explosion: {fileID: 7545598716694529264}
|
||||||
fuseTime: 2
|
fuseTime: 2
|
||||||
explosionLengthTime: 0.2
|
explosionLengthTime: 0.2
|
||||||
--- !u!1 &8211024835675607581
|
--- !u!1 &8211024835675607581
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,12 +2,23 @@
|
|||||||
|
|
||||||
public class BurriedItem : Diggable
|
public class BurriedItem : Diggable
|
||||||
{
|
{
|
||||||
public GameObject ItemToSpawn;
|
// Spawnpoint is optional, will spawn at location of dig spot, translated up
|
||||||
|
// on y-axis
|
||||||
public Transform Spawnpoint;
|
public Transform Spawnpoint;
|
||||||
|
public GameObject ItemToSpawn;
|
||||||
|
|
||||||
public override void Dig()
|
public override void Dig()
|
||||||
|
{
|
||||||
|
if (Spawnpoint == null)
|
||||||
|
{
|
||||||
|
Vector3 newPos = new Vector3(transform.position.x, transform.position.y + 0.2f, transform.position.z);
|
||||||
|
Instantiate(ItemToSpawn, newPos, transform.rotation, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Instantiate(ItemToSpawn, Spawnpoint.position, Spawnpoint.rotation, null);
|
Instantiate(ItemToSpawn, Spawnpoint.position, Spawnpoint.rotation, null);
|
||||||
|
}
|
||||||
|
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
// Put this on things that will explode when they enter the collision trigger
|
||||||
|
// an Explosion script
|
||||||
|
public class Explodable : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Light is optional (only if you want the exploded object to create light)
|
||||||
|
public Light explodeLight;
|
||||||
|
public ParticleSystem explodeParticle;
|
||||||
|
public float explosionLengthTime;
|
||||||
|
|
||||||
|
public void Explode()
|
||||||
|
{
|
||||||
|
if (explodeLight != null)
|
||||||
|
{
|
||||||
|
explodeLight.gameObject.SetActive(true);
|
||||||
|
explodeLight.transform.parent = null;
|
||||||
|
|
||||||
|
Destroy(explodeLight.gameObject, explosionLengthTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (explodeParticle != null)
|
||||||
|
{
|
||||||
|
explodeParticle.gameObject.SetActive(true);
|
||||||
|
explodeParticle.transform.parent = null;
|
||||||
|
//explodeParticle.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
|
||||||
|
explodeParticle.Play();
|
||||||
|
|
||||||
|
Destroy(explodeParticle.gameObject, explosionLengthTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0c0bbb84f48543046b86f073995c09b1
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
// Put this on an empty game object with a trigger collider. Anything inside of this
|
||||||
|
// trigger collider with an Explodable script will explode
|
||||||
|
public class Explosion : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
if (other != null)
|
||||||
|
{
|
||||||
|
Explodable explodable = other.GetComponent<Explodable>();
|
||||||
|
if (explodable != null)
|
||||||
|
{
|
||||||
|
explodable.Explode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fcf160d0f430fff438a4e57b70f778b2
|
||||||
@@ -4,6 +4,7 @@ public class Tnt : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public Light explodeLight;
|
public Light explodeLight;
|
||||||
public ParticleSystem explodeParticle;
|
public ParticleSystem explodeParticle;
|
||||||
|
public Explosion explosion;
|
||||||
|
|
||||||
public float fuseTime;
|
public float fuseTime;
|
||||||
public float explosionLengthTime;
|
public float explosionLengthTime;
|
||||||
@@ -17,6 +18,8 @@ void Update()
|
|||||||
if (!exploded && timer > fuseTime)
|
if (!exploded && timer > fuseTime)
|
||||||
{
|
{
|
||||||
exploded = true;
|
exploded = true;
|
||||||
|
explosion.gameObject.SetActive(true);
|
||||||
|
explosion.transform.parent = null;
|
||||||
explodeLight.gameObject.SetActive(true);
|
explodeLight.gameObject.SetActive(true);
|
||||||
explodeLight.transform.parent = null;
|
explodeLight.transform.parent = null;
|
||||||
explodeParticle.gameObject.SetActive(true);
|
explodeParticle.gameObject.SetActive(true);
|
||||||
@@ -26,6 +29,7 @@ void Update()
|
|||||||
|
|
||||||
Destroy(explodeLight.gameObject, explosionLengthTime);
|
Destroy(explodeLight.gameObject, explosionLengthTime);
|
||||||
Destroy(explodeParticle.gameObject, explosionLengthTime);
|
Destroy(explodeParticle.gameObject, explosionLengthTime);
|
||||||
|
Destroy(explosion.gameObject, 0.1f);
|
||||||
|
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user