I’ve got an Empty game object that will be an object spawner, but I need the objects that spawn to vary slightly along the x-axis some, to then instantiate. Using the code below, I’ve got it’s random position moving just fine using Random.Range, but it’s shifting the Empty game object with this script on it each time it instantiates an object, rather than instantiating the object at the different transform after changing it’s position in relations to the spawner.
private Transform newSpawnTransform;
void Start ()
{
newSpawnTransform = transform;
}
void randomForce()
{
newSpawnTransform.position += new Vector3 ((Random.Range (-.1f, .1f)), 0f, 0f);
}
Then I’m Calling the randomForce function, and instantiating the object when needed.
randomForce ();
Instantiate (object, newSpawnTransform);
Perhaps I just need clarification on how the transforms work, since it moves the parent object to instantiate the objects, rather than use the parent transform, then instantiate it nearby. I also looked at this question on how to instantiate objects without becoming a child in hopes of changing where it spawns, but couldn’t get it to work.