diff options
| author | Tom Harley | 2018-09-03 23:34:21 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-09-03 23:36:01 +0100 |
| commit | 5440734d820606b29a795c46172ade5d7eba8efb (patch) | |
| tree | 85867f40afb02cfa2a5028b515ed0a195866b7e9 /Assets/Scripts/Flyer.cs | |
| download | powerless-5440734d820606b29a795c46172ade5d7eba8efb.tar.gz powerless-5440734d820606b29a795c46172ade5d7eba8efb.zip | |
Initial commit
Diffstat (limited to 'Assets/Scripts/Flyer.cs')
| -rw-r--r-- | Assets/Scripts/Flyer.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Assets/Scripts/Flyer.cs b/Assets/Scripts/Flyer.cs new file mode 100644 index 0000000..dfb5f2e --- /dev/null +++ b/Assets/Scripts/Flyer.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Flyer : MonoBehaviour { + public Vector2 velocity = new Vector2(1, 0); + + private Rigidbody2D body; + + void Start() { + body = GetComponent<Rigidbody2D>(); + body.velocity = velocity; + } + + void OnTriggerEnter2D(Collider2D other) { + switch (other.gameObject.tag) { + case "Platform": + Flip(); + break; + } + } + + void OnTriggerStay2D(Collider2D other) { + GameObject ogo = other.gameObject; + switch (ogo.tag) { + case "Player": + CharacterControl cc = GetComponent<CharacterControl>(); + if (cc) cc.Damaged(); + break; + } + } + + void Flip() { + body.velocity = -body.velocity; + } + + void Update() { + transform.localScale = new Vector2(Mathf.Sign(body.velocity.x), 1); + } +} |
