- Home /
How do I make a cube teleport after dropping below a point?
Hi, I'm working on a simple project,and I'm new to Unity. I want a cube to drop and the player must avoid it. Then, after the cube reaches Y<-4.5, I want it to teleport to Y: 5, and the X is to be a randomly generated value between -2 and 4. If someone could provide me with the code I'd need, that would be really great (:
Thanks in advance!
What about Z? $$anonymous$$y answer below preserves the current Z value.
Answer by Huacanacha · Nov 23, 2013 at 12:38 AM
To facilitate your cube raining extravaganza please apply the following script to each cube:
void FixedUpdate() {
if (transform.position.y < -4.5f) {
transform.position = new Vector3(Random.Range(-2f,4f), 5f, transform.position.z);
}
}
Assets/Respawn.cs(1,6): error CS0116: A namespace can only contain types and namespace declarations
What now?
It needs to be in a C# class. Create a new C# script which will also generate the class code, delete the start and update functions and add this ins$$anonymous$$d.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122527im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
JavaScript Version of foreach (Touch touch in Input.touches) 1 Answer
Call JavaScript from c# Help! 0 Answers
Help, How can I get variables? 1 Answer