- Home /
How to trigger a specific object to start by pressing a button
So my character uses some special kind of shoes that for him to jump higher, it triggers water (water fountain). so I'm trying to make that when i press space to jump, it triggers the water fountain to activate, any script that could help me do that?
You need to read about accessing other game objects:
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Components.html
And the GetComponent() section here:
Answer by aman_jha · May 17, 2014 at 04:04 AM
On the water fountain, have an if code that runs on the update. If it's a particle system, have the base of the fountain instantiate the particle system. It would look like this:
if(Input.GetButtonDown="space"){
Instantiate(fountain_particle, new Vector3(0, 0, 0), Quaternion.identity);
}
The instantiate function might not work perfectly, so check it on your own for whatever type of code your're using.