using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Dragon : MonoBehaviour{ public GameObject colliderStop; public GameObject[] diable; public GameObject[] phase2Enable; public GameObject[] phase3Enable; public Vector2[] phasesPositions; public GameObject fire; public GameObject fireball; public int maxHp; public float hp; public Transform mouth; public CameraShake cameraShake; Animator anim; public int phase = 1; bool vulnerable; Transform player; Transform parent; // Start is called before the first frame update void Start(){ parent = GetComponentInParent(); anim = GetComponent(); hp = maxHp; vulnerable = false; player = GameObject.FindGameObjectWithTag("Player").GetComponent(); foreach(GameObject g in diable){ g.SetActive(false); } if(phase == 2){ anim.SetBool("Phase2", true); }else if(phase == 3){ anim.SetBool("Phase2", true); anim.SetBool("Phase3", true); } Invoke("DisableColliderStop", 2f); } void DisableColliderStop(){ colliderStop.SetActive(false); } float speed; // Update is called once per frame void Update(){ if(phase == 1){ if(hp <= 60){ phase = 2; anim.SetBool("Die", true); foreach (GameObject g in diable){ g.SetActive(false); } foreach (GameObject g in phase2Enable){ g.SetActive(true); } } }else if(phase == 2){ if (hp <= 30){ phase = 3; anim.SetBool("Die", true); foreach (GameObject g in diable){ g.SetActive(false); } foreach (GameObject g in phase3Enable){ g.SetActive(true); } } }else if(phase == 3){ if(hp <= 0){ Die(); } } } void Die(){ anim.SetBool("Die", true); } public void TakeDamage(float amt){ if (vulnerable){ hp = Mathf.Clamp(hp - amt, 0f, maxHp); } } public void IsIdle(){ vulnerable = true; } public void Shake(){ cameraShake.Shake(.1f, 1.5f); AudioManager.instance.Play("DragonShout"); } public void FireSound(){ AudioManager.instance.Play("DragonFire"); } public void FireAttack(){ vulnerable = false; Instantiate(fire, mouth.position, Quaternion.identity, mouth); } public void EndFireAttack(){ vulnerable = true; } public void FireBallAtack(){ AudioManager.instance.Play("DragonFireBall"); vulnerable = false; Instantiate(fireball, mouth.position, Quaternion.Euler(0, 0, 90f)); } public void EndFireBallAttack(){ vulnerable = true; } public void Win(){ StartCoroutine(WinScreen()); } IEnumerator WinScreen(){ yield return new WaitForSeconds(2f); SceneManager.LoadScene(0); } }