diff options
Diffstat (limited to 'Assets/Scripts/Bird.cs')
-rw-r--r-- | Assets/Scripts/Bird.cs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Assets/Scripts/Bird.cs b/Assets/Scripts/Bird.cs new file mode 100644 index 0000000..3f1aab4 --- /dev/null +++ b/Assets/Scripts/Bird.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Bird : MonoBehaviour { + + public float upForce = 200f; + + private bool isDead = false; + private Rigidbody2D rb2d; + private Animator anim; + + // Use this for initialization + void Start () + { + rb2d = GetComponent<Rigidbody2D>(); + anim = GetComponent<Animator>(); + } + + // Update is called once per frame + void Update () + { + if (isDead == false) + { + if (Input.GetMouseButtonDown(0)) // Left click + { + rb2d.velocity = Vector2.zero; + rb2d.AddForce(new Vector2(0, upForce)); + anim.SetTrigger("Flap"); + } + } + } + + void OnCollisionEnter2D(Collision2D collision) + { + rb2d.velocity = Vector2.zero; + isDead = true; + anim.SetTrigger("Die"); + GameControl.instance.BirdDied(); + } +} |