public void StartMakingNoise(NoiseMaker newNoiseMakerOwner, GameObject newNoiseOwner) { noiseMakerOwner = newNoiseMakerOwner; noiseOwner = newNoiseOwner; Destroy(gameObject, NoiseLifetime); }
public static NoiseMaker MakeNoise(Transform transform, float radius, GameObject instigator) { GameObject newObject = new GameObject(); newObject.transform.position = transform.position; newObject.name = "Noise!"; NoiseMaker newNoise = newObject.AddComponent <NoiseMaker>(); newNoise.instigator = instigator; newNoise.heardRadius = radius; newNoise.AlertNearby(); return(newNoise); }
private void OnTriggerEnter(Collider other) { // Player entered our perception! if (other.tag == "Player") { target = other.gameObject; // Cancel losing our target because we regained sight CancelInvoke("LoseSightOfTarget"); } // A sound has entered our perception! if (other.CompareTag("Perception")) { NoiseMaker newNoise = other.GetComponent <NoiseMaker>(); if (newNoise) { lastHeardNoise = newNoise; OnHeardSound.Invoke(lastHeardNoise); } } }