diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-07 22:57:48 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-07 22:57:48 +0200 |
commit | 09c0b2eed74a77010ba686061b147c9cace88ed6 (patch) | |
tree | 9b5c013fc7a679ccca3e2074773d29d7f1674bbc /td/Assets/Scripts/Projectile.cs | |
parent | 69a6cc2555d8dfc8314a08e6cef6b67fa1177bf0 (diff) | |
download | TD-09c0b2eed74a77010ba686061b147c9cace88ed6.tar.gz TD-09c0b2eed74a77010ba686061b147c9cace88ed6.zip |
Trur æ la te VCS, ikke meninga, men æ trur itj de e nå problem egt
Diffstat (limited to 'td/Assets/Scripts/Projectile.cs')
-rw-r--r-- | td/Assets/Scripts/Projectile.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/td/Assets/Scripts/Projectile.cs b/td/Assets/Scripts/Projectile.cs new file mode 100644 index 0000000..0cdef16 --- /dev/null +++ b/td/Assets/Scripts/Projectile.cs @@ -0,0 +1,42 @@ +using UnityEngine; + +public class Projectile : MonoBehaviour { + + public float Speed = 70f; + public int PointsPerHit; + [Header("Scripting vars")] + public Player Player; // Reference to the player object, should be set when instantiating + private Transform _target; + + public void Seek(Transform target) { + _target = target; + } + + + void Update () { + + if (_target == null) { + Destroy (gameObject); + return; + } + + Vector3 direction = _target.position - transform.position; + float distanceThisFrame = Speed * Time.deltaTime; + + if (direction.magnitude <= distanceThisFrame) { + HitTarget (); + return; + } + + transform.Translate (direction.normalized * distanceThisFrame, Space.World); + + + } + + void HitTarget() { + Player.ScoreAdd (PointsPerHit); + Destroy (_target.gameObject); + Destroy (gameObject); + } + +} |