Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using Unity.VisualScripting;
- using UnityEngine;
- public class BirdScript : MonoBehaviour
- {
- public AudioSource flap;
- public AudioSource dead;
- public LogicScript logic;
- public Rigidbody2D myRididbody;
- public SpriteRenderer wingflap;
- public float flapStrength;
- public bool BirdIsAlive = true;
- public float flaptimming = 1;
- private float flaptimer = 0;
- // Start is called before the first frame update
- void Start()
- {
- logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
- //Those two are from another tutorial to check if it works or not
- //dead = gameObject.AddComponent<AudioSource>();
- //flap = gameObject.AddComponent<AudioSource>();
- }
- // Update is called once per frame
- void Update()
- {
- //Moving the bird
- if (Input.GetKeyDown(KeyCode.Space) == true && BirdIsAlive)
- {
- myRididbody.velocity = Vector2.up * flapStrength ;
- flap.Play(0);
- }
- //Changes the wings so it looks like its flapping
- if (Input.GetKeyDown(KeyCode.Space)){
- if (flaptimer < flaptimming)
- {
- flaptimer = flaptimer + Time.deltaTime;
- wingflap.flipY = true;
- }
- else
- {
- flaptimer = 0;
- wingflap.flipY = false;
- }
- }
- //Detects if you flying too high or low
- if (transform.position.y > 17 || transform.position.y < -16)
- {
- Dying();
- logic.gameOver();
- //Seems like it does die if i fly too high or too low but it dosnt play the death sound
- //It does play the flap sound if i change it down in dying from dead.Play(); to flap.play() but apparently not if i fly
- //too high or too low
- }
- }
- private void OnCollisionEnter2D(Collision2D collision)
- {
- Dying();
- }
- void Dying()
- {
- logic.gameOver();
- BirdIsAlive = false;
- Debug.Log("Is it playing death sound?");
- dead.volume = 1.0f;
- dead.Play(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement