using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using System; public enum BossThugEnum { Pending=0, //waiting for npcs to die Talking=1, Attacking=2 } public class BossThug : MonoBehaviour { public GameObject npc1; public GameObject npc2; private GameObject player; private GameObject doorway; public Animator animator; private Rigidbody2D rb; public RuntimeAnimatorController newController; public bool isAfterConversation = false; // drop it if you can... public bool isDuringConversation = false; public BossThugEnum state = BossThugEnum.Pending; // Start is called before the first frame update void Start() { rb = GetComponent(); animator = GetComponent(); npc1 = GameObject.FindObjectsOfType(true).Where(sr => sr.gameObject.name == "ThugBob" && sr.gameObject.tag == "Enemy").ToArray()[0]; npc2 = GameObject.FindObjectsOfType(true).Where(sr => sr.gameObject.name == "ThugBen" && sr.gameObject.tag == "Enemy").ToArray()[0]; player = GameObject.FindGameObjectWithTag("Player"); doorway = GameObject.FindObjectsOfType(true).Where(sr => sr.gameObject.name == "DoorToHell" && sr.gameObject.tag == "SceneTransition").ToArray()[0]; if (npc1 == null || npc2 == null || player == null || doorway == null) { throw new Exception("Object has not been found in the scene"); } } // Update is called once per frame void Update() { if ( (npc1.GetComponent().health <= 0 && npc1.GetComponent().isKilled == 1) && (npc2.GetComponent().health <= 0 && npc2.GetComponent().isKilled == 1) && state == BossThugEnum.Pending) { state = BossThugEnum.Talking; // UZUPELNIC DIALOG } else if (state == BossThugEnum.Attacking && player.GetComponent().currentHealth <= 0) { doorway.GetComponent().ScenetToMoveTo(); PlayerPrefs.SetFloat("health-S", 10.0f); PlayerPrefs.SetFloat("health-S", 10.0f); } switch (state) { case BossThugEnum.Attacking: { ActivateKillingMode(); break; } case BossThugEnum.Talking: { ActivateDialogueMode(); //later add trigger events etc break; } } } private void ActivateKillingMode() { // set lower radious in order to less attack distance gameObject.GetComponent().radius = 2f; gameObject.GetComponent().enabled=true; animator.runtimeAnimatorController = Resources.Load("SampleScene/Enemies/BossThugAnimator.controller") as RuntimeAnimatorController; gameObject.GetComponent().baseAttack=1000f; } private void ActivateDialogueMode() { gameObject.GetComponent().radius = 4f; } public void ChanegStatusToAttack() { BreakConversation(); SetEndConversation(); state = BossThugEnum.Attacking; } public void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player" && state == BossThugEnum.Talking && !isAfterConversation && !isDuringConversation) { Debug.Log("OnTriggerEnter2D"); //gameObject.GetComponent().enabled = false; //gameObject.GetComponent().radius = 2f; isDuringConversation = true; gameObject.GetComponent().Dialogue.StartDialogue(); } } /*public void OnTriggerStay2D(Collider2D other) { if (other.tag == "Player" && state == BossThugEnum.Talking && !isAfterConversation && !isDuringConversation) { isDuringConversation = true; gameObject.GetComponent().Dialogue.StartDialogue(); } }*/ public void OnTriggerExit2D(Collider2D other) { if (other.tag == "Player" && state == BossThugEnum.Talking && !isAfterConversation && isDuringConversation) { //gameObject.GetComponent().enabled = true; //gameObject.GetComponent().radius = 2f; isDuringConversation = false; gameObject.GetComponent().Dialogue.BreakDialogueStep(); //TODO break dialogue after leaving collider range!!! } } /// /// Set as action invoked in event after 'NpcDialogueManager::SetNextDialogue()' function to adjust Trigger2D event listening /// public void BreakConversation() { isDuringConversation = false; } /// /// Mark conversation as finished /// public void SetEndConversation() { isAfterConversation = true; } }