public void isEnemy(GameObject attacker) { Ray ray = new Ray(attacker.transform.position, attacker.transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, 2.0f)) { hasAttacked = true; TurnController.takeAction(); GameObject t = Instantiate(prefab, hit.collider.gameObject.transform.position, hit.collider.gameObject.transform.rotation); if (checkAttack(hit)) { int damage = Dice.d8(1)[0]; t.GetComponent <TextMesh> ().text = damage.ToString(); GameObject hitObject = hit.transform.gameObject; DeathController target = hitObject.GetComponent <DeathController> (); if (target != null) { enemyStats.setHealth(damage); if (enemyStats.getHealth() <= 0) { target.reactToHit(); } } } else { t.GetComponent <TextMesh> ().text = "MISS"; } } }
public void isEnemy(GameObject attacker) { Ray ray = new Ray(attacker.transform.position, attacker.transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, 2.0f)) { GameObject hitObject = hit.transform.gameObject; DeathController target = hitObject.GetComponent <DeathController> (); if (target != null) { target.reactToHit(); } } }