- Home /
Trigger Falling Object
To be more precise, I am creating a Horror Game. An was thinking of making an object (Scary dead guy) fall down. I was thinking of making it so while the player is moving. An invisible ground trigger is triggered and the object falls. Is that possible? An if so, how? Thanks in return. An I'm kinda still new to Unity. (I can use Scripts fine though) so explain briefly please. Thanks.
Answer by adrenak · Sep 10, 2012 at 04:44 AM
Hi, You can follow these steps to do it
1) Have a trigger to detect the player. Identifiy the player using a tag or its game object name
2) Have a script in the trigger. It primarily takes two variables, one is a Transform object which you position in the level where you want the dead man to be put and the other in a GameObject which can be a prefab of the dead guys' body.
3) Use Instantiate to spawn the dead guy at the Transform variables position.
Here's a script :
var pos : Transform;
var deadGuy : GameObject; //a prefab of the dead guy
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "Player")
Instantaite(deadGuy, pos.position, pos.rotation);
}
Assign this script to the trigger. Then make an empty game object and position it in the level where you want the dead guy to appear.Drag this empty gameObject from heirarchy to the variable `pos` in the inspector window of the trigger.
You also need to have the dead guy ( it can be anything, a horse, soda can etc) as a prefab, or it can be present anywhere in the game world. Drag it to the variable `deadGuy` in the script attached to the trigger. The last thing is, tag the player as "`Player`" from the inspector window.
Tell me if you don't follow. Hope this helps!
Like I said, I'm new. So this is a bit confusing, can you work it step by step for me please?
I'm getting these errors after pasting the script and saving it: UCE0001: ';' expected. Insert a semicolon at the end. BCE0043: Unexpected token: Collider. and BCE0043: Unexpected token: ;.
$$anonymous$$ade some change there, had punctuation errors
Now I'm getting: BCE0005: $$anonymous$$ identifier: 'Instantaite'.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080836im_/https://answers.unity.com/themes/thub/images/avi.jpg)