- Home /
Stealth Tutorial - gameController
i was learning from one of your tutorials: unity stealth 4x: gameController. I have done everything right and there are no errors on my console, but when i hit play and change the position of x, y or z in the script component in gameController, the alarm doesn't go off. i changed the FindChild to just Find as well. Still no luck. I have unity 4.5 i have pasted a copy of the script that i am using below. Could you please have a look. Thank you in advance.
using UnityEngine; using System.Collections;
public class LastPlayerSighting : MonoBehaviour { public Vector3 position = new Vector3(1000f, 1000f, 1000f); public Vector3 resetPosition = new Vector3(1000f, 1000f, 1000f); public float lightHighIntensity = 0.25f; public float lightLowIntensity = 0f; public float fadeSpeed = 7f; public float musicFadeSpeed = 1f;
private AlarmLight alarm;
private Light mainLight;
private AudioSource panicAudio;
private AudioSource[] sirens;
void Awake()
{
alarm = GameObject.FindGameObjectWithTag(Tags.alarm).GetComponent<AlarmLight>();
mainLight = GameObject.FindGameObjectWithTag(Tags.mainLight).light;
panicAudio = transform.Find ("secondaryMusic").audio;
GameObject[] sirenGameObjects = GameObject.FindGameObjectsWithTag(Tags.siren);
sirens = new AudioSource[sirenGameObjects.Length];
for(int i = 0; i < sirens.Length; i++)
{
sirens[i] = sirenGameObjects[i].audio;
}
}
void update()
{
SwitchAlarms();
MusicFading();
}
void SwitchAlarms()
{
alarm.alarmOn = (position != resetPosition);
float newIntensity;
if(position != resetPosition)
{
newIntensity = lightLowIntensity;
}
else
{
newIntensity = lightHighIntensity;
}
mainLight.intensity = Mathf.Lerp (mainLight.intensity, newIntensity, fadeSpeed * Time.deltaTime);
for(int i = 0; i < sirens.Length; i++)
{
if(position != resetPosition && !sirens[i].isPlaying)
{
sirens[i].Play();
}
else if(position == resetPosition)
{
sirens[i].Stop();
}
}
}
void MusicFading()
{
if(position != resetPosition)
{
audio.volume = Mathf.Lerp(audio.volume, 0f, musicFadeSpeed * Time.deltaTime);
panicAudio.volume = Mathf.Lerp(panicAudio.volume, 0.8f, musicFadeSpeed * Time.deltaTime);
}
else
{
audio.volume = Mathf.Lerp(audio.volume, 0.8f, musicFadeSpeed * Time.deltaTime);
panicAudio.volume = Mathf.Lerp(panicAudio.volume, 0f, musicFadeSpeed * Time.deltaTime);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612002816im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Does anyone have any experience scripting trees onto a heightmap? 1 Answer
Make Script Component Do Things Even When Game Is Closed 2 Answers
Loading Scripts from asset bundle in iOS and WebGL. 0 Answers
How do i make the player to walk to where the mouse cursor position was clicked ? 0 Answers
What's wrong? 1 Answer