diff options
Diffstat (limited to 'AlienSurvival/Assets/Scripts/Test/TestGrenade.cs')
-rw-r--r-- | AlienSurvival/Assets/Scripts/Test/TestGrenade.cs | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs b/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs new file mode 100644 index 0000000..a1434d8 --- /dev/null +++ b/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs @@ -0,0 +1,107 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestPseudoVec3 +{ + public float x; + public float y; + public float h; + public TestPseudoVec3(float x, float y, float h) + { + this.x = x; + this.y = y; + this.h = h; + } +} + +public class TestGrenade : MonoBehaviour +{ + public bool useGravity; + + public float gravity = -9.8f; + + public TestPseudoVec3 velocity; + public TestPseudoVec3 pseudoPos; + + public Transform shadow; + + private bool m_IsGround + { + get + { + return pseudoPos.h <= 0; + } + } + + // Start is called before the first frame update + void Start() + { + //Invoke("Dead", 3); + } + + void Dead() + { + if (this.gameObject) + { + GameObject.Destroy(this.gameObject); + } + } + + // Update is called once per frame + void Update() + { + if(useGravity && !m_IsGround) + { + velocity.h += gravity * Time.deltaTime; + } + + pseudoPos.x += velocity.x * Time.deltaTime; + pseudoPos.y += velocity.y * Time.deltaTime; + pseudoPos.h += velocity.h * Time.deltaTime; + + if(m_IsGround) + { + velocity.h = -velocity.h; + pseudoPos.h = 0; + } + + Vector3 position = transform.position; + + position.x = pseudoPos.x; + position.y = pseudoPos.y + pseudoPos.h; + + transform.position = position; + + if (shadow) + { + // shadow position + shadow.rotation = Quaternion.identity; + Vector3 shadowPos = Vector3.zero; + shadowPos.x = pseudoPos.x; + shadowPos.y = pseudoPos.y; + shadowPos.z = 0; + shadow.position = shadowPos; + } + } + + private void OnTriggerEnter2D(Collider2D collision) + { + //GameObject go = collision.gameObject; + + //if (!go.CompareTag("enemy")) + //{ + // return; + //} + + //GameObject.Destroy(collision.gameObject); + + ////this.gameObject.SetActive(false); + + //if (this.gameObject) + //{ + // GameObject.Destroy(this.gameObject); + //} + } + +} |