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.

51 lines
1.4 KiB

2 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bird : MonoBehaviour
{
const float horizontalSpeed = 100f;
2 years ago
const float verticalSpeed = 5f;
const float amplitude = 30f;
private float startTime;
float _startingY;
[SerializeField] Sprite _blueBird;
[SerializeField] Sprite _yellowBird;
DragonMovement.AttackType _attackType;
public DragonMovement.AttackType AttackType { get => _attackType; set => _attackType = value; }
void Start()
{
startTime = Time.time;
_startingY = transform.position.y;
int type = Random.Range(0, 2);
if (type == 0) {
AttackType = DragonMovement.AttackType.CONE;
GetComponent<SpriteRenderer>().sprite = _blueBird;
}
else
{
AttackType = DragonMovement.AttackType.FIREBALL;
GetComponent<SpriteRenderer>().sprite = _yellowBird;
}
}
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);
}
}