- Home /
Question by
djbenspoon · Feb 21, 2013 at 02:47 PM ·
java
How do you collect a GameObject and make it Spawn somewhere else?
Basically I'm developing a simple Snake Game very similar to "Curve Fever". I need a power up that I can collect, and will spawn in another random location in a random number of second.
Any idea on how to script this?
Thanks in advance
Comment
Best Answer
Answer by robertbu · Feb 21, 2013 at 03:53 PM
Hide it and then show it again later in a new position:
function OnCollisionEnter(collision : Collision )
{
if (collision.collider.name == "Player") {
collision.collider.enabled = false;
renderer.enabled = false;
yield WaitForSeconds(Random.Range(3.0, 6.0));
// Whatever placement code you want
transform.position = Random.insideUnitSphere * 5.0;
collision.collider.enabled = true;
renderer.enabled = true;
}
}
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Timer help please 1 Answer
No headbob when jumping 1 Answer