- Home /
Randomly spawn a trigger area
Hi, im making a horror game where you walk around in a maze (randomly generated) and the main goal is to get out. Im almost finished but i want to spawn a trigger area somewhere in the maze so that i can have a jumpscare of some sort. is this do-able? (Giggity)
yea... pick a random point in the bounds of the maze, check to see if there is a collider there or just terrain. If there is a collider pick another random point. once you find an empty area spawn a trigger prefab.
ok but i want the location of the trigger to be different every time, do you know how to do that?
its a random point. it would be different everytime. :P
Well or at least every point in the maze would have an equal chance of being chosen every time.
i now realized how stupid i am and that the first comment was exactly what i was looking for...
Answer by Montraydavis · Nov 16, 2012 at 12:04 AM
This here will create a Random Collider in a random place.
Step 1. Create an Empty GameObject, rename.
Step 2. Add a Collider to it
Step 3. Create a new Prefab, and add the new GameObject ( be sure to have it in folder "Resources" . It can be a child of any folder. Just kind in mind what directories you are using. )
Step 4. Execute the code here
function CreateRandomCollider ( )
{
var RandomPos : Vector3 = Vector3 ( Random.Range(min,max), Random.Range(min,max), Random.Range(min,max) ) ;
var rancollinstance : GameObject = Instantiate ( Resources.Load("PrefabColliderYouCreatedWithoutExtension"), RandomPos, Quaternion.identity ) ;
}
Set your 'min,max', and execute the code above.
Something to kind in mind though is that the script does not provide any kind of support for making sure the collider is spawned on the terrain/mesh. That part, you will need to do.
I hope this helps you with your issue, and feel free to ask any questions if this has not solved your issue.
Thanks for supporting Unity3D
~Montray
hi i need help with something kinda like this, i wanna activate a trigger with a trigger.. so when i explore a room nothing happens, when i exit and enter again, a ghost will jump out
Your answer
Follow this Question
Related Questions
Jumpscare (Triggers and stuff) 1 Answer
Random Trigger placement? 1 Answer
Trigger an animation 1 Answer
Starting a roguelike, maze generator problem. 1 Answer
How do you make a trig object? 0 Answers