using System.Collections; using System.Collections.Generic; using UnityEngine; public class Bird : MonoBehaviour { const float horizontalSpeed = 100f; 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().sprite = _blueBird; } else { AttackType = DragonMovement.AttackType.FIREBALL; GetComponent().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); } }