|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class Bird : MonoBehaviour
|
|
|
|
{
|
|
|
|
const int CHANCE_FOR_BOOST = 30; //out of 100
|
|
|
|
const float horizontalSpeed = 100f;
|
|
|
|
const float verticalSpeed = 5f;
|
|
|
|
const float amplitude = 30f;
|
|
|
|
|
|
|
|
private float startTime;
|
|
|
|
float _startingY;
|
|
|
|
[SerializeField] Sprite _boostBird;
|
|
|
|
[SerializeField] Sprite _fireBird;
|
|
|
|
DragonMovement.AttackType _attackType;
|
|
|
|
|
|
|
|
public DragonMovement.AttackType AttackType { get => _attackType; set => _attackType = value; }
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
startTime = Time.time;
|
|
|
|
_startingY = transform.position.y;
|
|
|
|
|
|
|
|
int r = Random.Range(0, 100);
|
|
|
|
|
|
|
|
int type = r < CHANCE_FOR_BOOST ? 0 : 1;
|
|
|
|
|
|
|
|
if (type == 0) {
|
|
|
|
AttackType = DragonMovement.AttackType.CONE;
|
|
|
|
GetComponent<SpriteRenderer>().sprite = _boostBird;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AttackType = DragonMovement.AttackType.FIREBALL;
|
|
|
|
GetComponent<SpriteRenderer>().sprite = _fireBird;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
float y = _startingY + (amplitude * Mathf.Sin(verticalSpeed * (Time.time - startTime)));
|
|
|
|
transform.position = new Vector3(transform.position.x - Time.deltaTime * horizontalSpeed, y, transform.position.z);
|
|
|
|
|
|
|
|
if (transform.position.x < -100f)
|
|
|
|
{
|
|
|
|
GameObject.Destroy(this.gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Eat()
|
|
|
|
{
|
|
|
|
GameObject.Destroy(this.gameObject);
|
|
|
|
}
|
|
|
|
}
|