public void Shoot() { AkSoundEngine.PostEvent("hunter_rifle", gameObject); Vector3 position = agent.transform.position; Vector3 direction = agent.transform.forward; RaycastHit hit; if (Physics.Raycast(position, direction, out hit, shootingRange, shootingMask)) { Debug.Log(hit.collider.gameObject); AIAgent agent = hit.collider.gameObject.GetComponent <AIAgent>(); if (agent != null) { agent.Kill(); } else { Cannibal cannibal = hit.collider.gameObject.GetComponentInParent <Cannibal>(); if (cannibal != null) { cannibal.Kill(); } else { Bush bush = hit.collider.gameObject.GetComponent <Bush>(); if (bush != null) { Debug.Log("Killing cannibals in bush:" + bush); bush.KillACannibal(); } } } } }
protected override void OnExecute() { Vector3 position = agent.transform.position; Vector3 direction = agent.transform.forward; RaycastHit hit; if (Physics.Raycast(position, direction, out hit, distance.value, mask.value)) { Debug.Log(hit.collider.gameObject); AI.AIAgent agent = hit.collider.gameObject.GetComponent <AI.AIAgent>(); if (agent != null) { agent.Kill(); } else { Cannibal cannibal = hit.collider.gameObject.GetComponentInParent <Cannibal>(); if (cannibal != null) { cannibal.Kill(); } else { Bush bush = hit.collider.gameObject.GetComponent <Bush>(); if (bush != null) { bush.KillACannibal(); } } } } EndAction(); }