- Home /
Spawn One Game Object In A Random Location After Object Has Been Used
Hey guys, this is my first question to ask the community so bear with me. I am creating a game where a pillar shows up on the battlefield and the player must interact with it before it respawns to another location. My question is; where do I start to just make the object show up in one spawn location, then appear in another? I appreciate any help given. I am not an experienced programmer but I do understand the basics of C#.
Rather than respawn anything, just hide/show/move the object. Research:
Transform.position
Renderer.enabled
Collider.enabled
You may want to look at colliders, triggers, OnTriggerEnter() for interacting with the pillar.
Wow thanks guys. Those are great places for me to start. I appreciate the help.
If the object is hidden will the players or AI run into it?
If you turn off the collider, then neither the player or the AI will run into it. Note you could also disable it completely with GameObject.SetActive(). The only issue with disabling something completely is that many of the functions used to find game object will not find a disabled object.
Answer by mattyman174 · Feb 22, 2014 at 04:10 AM
Use the Objects transform position to set a new position for it.
transform.position = newLocationAsAVector3;
Have not tried this yet but have seen it in action. Will probably use this come time. Thank you.
Your answer
Follow this Question
Related Questions
C# Random spawn from an array 0 Answers
[solved] respawn when destroyed 1 Answer
Randomly Initiate Cubes - Prevent Same Position 0 Answers
Respawn random objects 1 Answer