Hello, this is a basic question, but if I want to have a trigger (button, collision, etc.) to activate another script, how would I do that? How would I limit the amount of time the script would be activate? An example would be: The player hits a button and a "constant force" script is activated for 5 seconds (to simulate nitrous oxide in a car). Thanks.
1 Answer
1Would it be something like this you are looking for?
function Update ()
{
if (Input.GetKey(KeyCode.Space) && nosReady)
NOS();
}
function NOS()
{
nosReady = false;
nosActive = true;
yield WaitForSeconds(5);
nosActive = false;
yield WaitForSeconds(5);
nosReady=true;
}
function FixedUpdate()
{
if (nosActive)
{
//Add force
}
}
You would use gameObject.AddComponent(TheNameOfTheScript); But if you are that new to unity, I would suggest poking around in the http://unity3d.com/support/documentation/ScriptReference/
– Atnas1010