40 lines
1018 B
C#
40 lines
1018 B
C#
using UnityEngine;
|
|
|
|
public class BirdScript : MonoBehaviour
|
|
{
|
|
public Rigidbody2D myRigidbody;
|
|
public float flapStrength;
|
|
public LogicScript logic;
|
|
public bool birdIsAlive = true;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
public void jump()
|
|
{
|
|
myRigidbody.linearVelocity = Vector2.up * flapStrength;
|
|
|
|
}
|
|
void Update()
|
|
{
|
|
if(Input.GetKeyDown(KeyCode.Space) && birdIsAlive)
|
|
{
|
|
myRigidbody.linearVelocity = Vector2.up * flapStrength;
|
|
}
|
|
if(transform.position.y > 16 || transform.position.y < -16)
|
|
{
|
|
logic.gameOver();
|
|
birdIsAlive = false;
|
|
}
|
|
}
|
|
private void OnCollisionEnter2D(Collision2D other)
|
|
{
|
|
logic.gameOver();
|
|
birdIsAlive = false;
|
|
}
|
|
}
|