From 5440734d820606b29a795c46172ade5d7eba8efb Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 3 Sep 2018 23:34:21 +0100 Subject: Initial commit --- Assets/Scripts/Flyer.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Assets/Scripts/Flyer.cs (limited to 'Assets/Scripts/Flyer.cs') 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(); + 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(); + if (cc) cc.Damaged(); + break; + } + } + + void Flip() { + body.velocity = -body.velocity; + } + + void Update() { + transform.localScale = new Vector2(Mathf.Sign(body.velocity.x), 1); + } +} -- cgit v1.2.1