Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- // Start is called before the first frame update
- void Start()
- {
- logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
- }
- // Update is called once per frame
- void Update()
- {
- // Check if the bird goes off-screen
- if (transform.position.y > ScreenUtils.ScreenTop || transform.position.y < ScreenUtils.ScreenBottom)
- {
- // Trigger game over if the bird goes off-screen
- logic.gameOver();
- birdIsAlive = false;
- }
- // Bird flap input
- if (Input.GetKeyDown(KeyCode.Space) && birdIsAlive)
- {
- myRigidBody.velocity = Vector2.up * flapStrength;
- }
- }
- private void OnCollisionEnter2D(Collision2D collision)
- {
- logic.gameOver();
- birdIsAlive = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement