summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Bird.cs
diff options
context:
space:
mode:
authorMarvin Borner2018-05-23 17:39:17 +0200
committerMarvin Borner2018-05-23 17:39:17 +0200
commit47c3a3275c5eb110c10933bc3dceb5eb3b89eb72 (patch)
treef74d8562441d7bcbf5c5d8f39d8eed3578161426 /Assets/Scripts/Bird.cs
Added basic jumping and background moving
Diffstat (limited to 'Assets/Scripts/Bird.cs')
-rw-r--r--Assets/Scripts/Bird.cs41
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();
+ }
+}