using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdScript : MonoBehaviour
{
public static BirdScript instance;
[SerializeField]
private Rigidbody2D MyRigidbody;
[SerializeField]
private Animator Anim;
private float Speed = 3f;
private float BounceSpeed = 4f;
private bool didFlap;
public bool isAlive;
void Awake()
{
if (instance == null)
{
instance = this;
}
isAlive = true;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
if (isAlive)
{
Vector3 temp = transform.position;
temp.x += Speed * Time.deltaTime;
transform.position = temp;
if (didFlap)
{
didFlap = false;
MyRigidbody.velocity = new Vector2(0, BounceSpeed);
Anim.SetTrigger("flap");
}
if (MyRigidbody.velocity.y >= 0)
{
transform.rotation = Queternion.Euler(0, 0, 0);
}
else
{
float angle = 0;
angle = Mathf.Lerp(0, -90, -MyRigidbody.velocity.y / 7);
transform.rotation = Quaternion.Euler(0, 0, angle);
}
}
}
public void uc()
{
didFlap = true;
}
}