- Home /
how to loop an object in a 2D game
I am working on a 2d game and I have a helicopter that starts off screen and then moves across the screen. Once the copter gets off the screen I need it to loop around in a new random position that appears in the screen. This obviously gives the illusion that there are many enemies. Can someone help me with the script for this? Thanks!
Have bounds set and if the object that goes out of the bounds then have its transform components reset to some random range and ensure this range is in the range of the bound.
Um, I implemented that into my update and then start methods, but only the audio of my enemy is existing, I can't see a helicopter on the screen now. Any ideas?
Answer by jprocha101 · Dec 03, 2015 at 06:19 AM
You can set the transform.position back to the orignal position with a different Y value once the object is off screen. Example is when your object is moving from left to right with a total screen width of 20 units camera centered on 0,0
if (transform.position.x > 10)
{
transform.position = new Vector2(-10,2);
}
If the original y was 0 then the new one can be 2. That would give the illusion that it's a different game object.
Your answer

Follow this Question
Related Questions
OnMouseOver() right click cursor - not triggering the code 1 Answer
Want to make GameObject follow another GameObject's path Unity3D 1 Answer
How to get objects with the same script to act independently? 2 Answers
Player Sliding without any Input 2 Answers
How to maintain speed on the x axis according the last key pressed ? 2 Answers