diff options
Diffstat (limited to 'AlienSurvival/Assets/Scripts/Test/TestBomb.cs')
-rw-r--r-- | AlienSurvival/Assets/Scripts/Test/TestBomb.cs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/AlienSurvival/Assets/Scripts/Test/TestBomb.cs b/AlienSurvival/Assets/Scripts/Test/TestBomb.cs new file mode 100644 index 0000000..77933f4 --- /dev/null +++ b/AlienSurvival/Assets/Scripts/Test/TestBomb.cs @@ -0,0 +1,67 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestBomb : MonoBehaviour +{ + + [SerializeField] private float m_GravityScale = 1f; + + [SerializeField] private GameObject m_ExplosionEffect; + + private TopDownTransform m_Coords; + + private Vector3 GRAVITY = new Vector3(0, 0, -9.8f); + + private Vector3 m_Velocity; // x, y, fakeHeight + + /// <summary> + /// 设置初始参数,都在fake空间下 + /// </summary> + /// <param name="initPosition"></param> + /// <param name="initDirection"></param> + /// <param name="initSpeed"></param> + public void Set(Vector3 initPosition, Vector3 initDirection, float initSpeed) + { + m_Coords = GetComponent<TopDownTransform>(); + m_Coords.position = initPosition; + + m_Velocity = initDirection * initSpeed; + } + + private void Update() + { + Vector3 move = m_Velocity * Time.deltaTime; + + if (m_Velocity.magnitude > 0 && m_Coords.z + move.z >= 0) + { + m_Coords.x += move.x; + m_Coords.y += move.y; + m_Coords.z += move.z; + m_Velocity += GRAVITY * Time.deltaTime; + + //transform.rotation *= Quaternion.Euler(0, 0, 20 * m_Velocity.magnitude * Time.deltaTime); + } + else + { + m_Velocity = Vector3.zero; + + this.gameObject.SetActive(false); + Destroy(this.gameObject); + PlayExplosion(); + } + } + + private void PlayExplosion() + { + GameObject exp = Instantiate<GameObject>(m_ExplosionEffect); + + TopDownTransform coord = exp.GetComponent<TopDownTransform>(); + coord.position = m_Coords.position; + + exp.GetComponent<TopDownSorting>().Sorting(); + + exp.SetActive(true); + } + +} |