//private GameObject BlueBoar; // Start is called before the first frame update void Start() { smallMonsterHealth = GetComponent <SmallMonsterHealth>(); //BlueBoar = GameObject.Find("BlueBoar"); healthBar = gameObject.transform.Find("EnemyCanvas").transform.Find("MonsterHealthBG").transform.Find("MonsterHealth").GetComponent <Image>();//("Blue/EnemyCanvas/MonsterHealthBG/MonsterHealth").GetComponent<Image>(); //healthBar = transform.GetChild(2).GetChild(0).GetChild(0).GetComponent<Image>(); }
void Hit()/*public void OnTriggerEnter(Collider other)*/ { //find the closest small monster //float distance = Mathf.Infinity; //Vector3 position = transform.position; //foreach (GameObject smallMonster in smallMonsters) //{ // Vector3 diff = smallMonster.transform.position - position; // float curDistance = diff.sqrMagnitude; // if (curDistance < distance) // { // closestSmallMonster = smallMonster; // } //} // find the closest big monster //foreach (GameObject bigMonster in bigMonsters) //{ // Vector3 diff = bigMonster.transform.position - position; // float curDistance = diff.sqrMagnitude; // if (curDistance < distance) // { // closestBigMonster = bigMonster; // } //} // detect if in the attacking stages bool attack = anim.GetBool("Attack1") || anim.GetBool("Attack2") || anim.GetBool("Attack3"); if ((Vector3.Distance(transform.position, bigMonster0.transform.position) <= 6f) && (attack)) { //Debug.Log("Here is executed"); BigMonsterHealth bigMonsterHealth = bigMonster0.GetComponent <BigMonsterHealth>(); if (currentConfidenceState == "Low Confidence") { amount = lowConfiAttack; } else if (currentConfidenceState == "Normal Confidence") { amount = normalConfiAttack; } else { amount = normalConfiAttack; } bigMonsterHealth.TakeDamage(amount); } if ((Vector3.Distance(bigMonster1.transform.position, transform.position) <= 3f) && (attack)) { BigMonsterHealth bigMonsterHealth = bigMonster1.GetComponent <BigMonsterHealth>(); if (currentConfidenceState == "Low Confidence") { amount = lowConfiAttack; } else if (currentConfidenceState == "Normal Confidence") { amount = normalConfiAttack; } else { amount = normalConfiAttack; } Debug.Log("Ruth is taking damage"); bigMonsterHealth.TakeDamage(amount); } if ((Vector3.Distance(bigMonster2.transform.position, transform.position) <= 3f) && (attack)) { BigMonsterHealth bigMonsterHealth = bigMonster2.GetComponent <BigMonsterHealth>(); if (currentConfidenceState == "Low Confidence") { amount = lowConfiAttack; } else if (currentConfidenceState == "Normal Confidence") { amount = normalConfiAttack; } else { amount = normalConfiAttack; } Debug.Log("Ruth is taking damage"); bigMonsterHealth.TakeDamage(amount); } if ((Vector3.Distance(smallMonster0.transform.position, transform.position) <= 3f) && (attack)) { SmallMonsterHealth smallMonsterHealth = smallMonster0.GetComponent <SmallMonsterHealth>(); if (currentConfidenceState == "Low Confidence") { amount = lowConfiAttack; } else if (currentConfidenceState == "Normal Confidence") { amount = normalConfiAttack; } else { amount = normalConfiAttack; } Debug.Log("Ruth is taking damage"); smallMonsterHealth.TakeDamage(25); } if ((Vector3.Distance(smallMonster1.transform.position, transform.position) <= 3f) && (attack)) { SmallMonsterHealth smallMonsterHealth = smallMonster1.GetComponent <SmallMonsterHealth>(); if (currentConfidenceState == "Low Confidence") { amount = lowConfiAttack; } else if (currentConfidenceState == "Normal Confidence") { amount = normalConfiAttack; } else { amount = normalConfiAttack; } Debug.Log("Ruth is taking damage"); smallMonsterHealth.TakeDamage(25); } if ((Vector3.Distance(smallMonster2.transform.position, transform.position) <= 3f) && (attack)) { SmallMonsterHealth smallMonsterHealth = smallMonster2.GetComponent <SmallMonsterHealth>(); if (currentConfidenceState == "Low Confidence") { amount = lowConfiAttack; } else if (currentConfidenceState == "Normal Confidence") { amount = normalConfiAttack; } else { amount = normalConfiAttack; } Debug.Log("Ruth is taking damage"); smallMonsterHealth.TakeDamage(25); } }