-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBirdScript.cs
More file actions
32 lines (27 loc) · 798 Bytes
/
BirdScript.cs
File metadata and controls
32 lines (27 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdScript : MonoBehaviour
{
public Rigidbody2D myRigidbody;
public float flapStrength;
public LogicScript logic;
public bool birdIsAlive = true;
void Start()
{
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && birdIsAlive)
{
myRigidbody.linearVelocity = Vector2.up * flapStrength;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("Logic reference is: " + (logic == null ? "NULL" : logic.name));
logic.gameOver();
birdIsAlive = false;
}
}