- Home /
How to activate another script?
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.
Answer by Atnas1010 · Nov 05, 2010 at 04:05 AM
Would 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 } }
While a NOS type boost was one of the things I had in $$anonymous$$d, I meant triggering a completely separate script that is in the scene. Also, I am new to unity, so I dont even know what to do with your script (how would I make it work)?
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/