You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
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);
|
|
}
|
|
}
|