diff options
author | chai <chaifix@163.com> | 2022-04-11 19:15:08 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-04-11 19:15:08 +0800 |
commit | f593891db65ac0faf775cd6b393460c6c917cd33 (patch) | |
tree | ba6fa5de5db66f88699e473997bd07276109e065 /AlienSurvival/Assets/Test/Scripts/TestLauncher.cs | |
parent | 680b483c63b02a45d24d6537c9f6c0cdb8e3365b (diff) |
*misc
Diffstat (limited to 'AlienSurvival/Assets/Test/Scripts/TestLauncher.cs')
-rw-r--r-- | AlienSurvival/Assets/Test/Scripts/TestLauncher.cs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/AlienSurvival/Assets/Test/Scripts/TestLauncher.cs b/AlienSurvival/Assets/Test/Scripts/TestLauncher.cs new file mode 100644 index 0000000..f053854 --- /dev/null +++ b/AlienSurvival/Assets/Test/Scripts/TestLauncher.cs @@ -0,0 +1,67 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestLauncher : MonoBehaviour +{ + public TestGrenade bullet; + + public Transform shadow; + + public Transform start; + + public float speed = 1; + + SpriteRenderer sprite; + + // Start is called before the first frame update + void Start() + { + sprite = GetComponent<SpriteRenderer>(); + } + + // Update is called once per frame + void Update() + { + + Vector3 screenPos = Input.mousePosition; + + Vector2 target = Camera.main.ScreenToWorldPoint(screenPos); + + Vector2 dir = Vector2.ClampMagnitude(target - (Vector2)transform.position, 1); + Vector3 move = dir * speed * Time.deltaTime; + + float x = move.x; + if (x > 0) + { + sprite.flipY = false; + } + else if (x < 0) + { + sprite.flipY = true; + } + + transform.rotation = Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x)); + + Shot(); + } + + void Shot() + { + if (Input.GetButtonDown("Fire1")) + { + //Debug.Log("Shoot"); + + TestGrenade b = TestGrenade.Instantiate(bullet); + b.gameObject.SetActive(true); + + b.transform.position = start.position; + + b.pseudoPos = new TestPseudoVec3(start.position.x, start.position.y, 0.1f); + + float speed = 5; + b.velocity = new TestPseudoVec3(transform.right.x * speed, transform.right.y * speed, 3f); + } + } + +} |