- Home /
(Unity 2D C#) Move instantiated prefab on Y axis?
Hi, To get straight to it, How can I move an instantiated prefab on the Y axis? I've been trying some to use AddForce() and transform.Translate(0, 1, 0), but for some reason they're not working.
Here is my script to instantiate the prefab...
void scrollBackground()
{
Debug.Log("Moving object...");
//To move prefab
obstacle.transform.Translate (0, 1, 0);
}
How can I fix this?
Answer by FlaflaTwo · Apr 21, 2014 at 04:40 PM
That is correct code. One thing you can try is check if the object is rotated - you could just be moving the object away from the camera since Transform.Translate works in a local space by default. Try and confirm this by looking at the scene view in-game.
To force Unity to translate on a global scale, do this:
obstacle.transform.Translate (0, 1, 0, Space.World);
Your answer
Follow this Question
Related Questions
Instantiate prefab (button, texture) with attached script 1 Answer
The variable othertransform of Prefab has not been assigned 2 Answers
Problem with GetComponentinChildren and Instantiate 0 Answers
How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer
Having multiple objects fire prefabs in different times C# 0 Answers