- Home /
Object wont move via script (C#) after Instantiated via script
GameObject tempObject = Instantiate(Resources.Load(attributes.modelName)) as GameObject;
// Set name of the model and the tag
tempObject.name = "playerShipModel";
tempObject.tag = "player";
// Doesn't work. Ship does not move?
//tempObject.transform.rigidbody.position = new Vector3(50.0f,0f,0f);
// Issue is the model wont set to the right area and what not. gotta figure out why.
GameObject model = GameObject.Find("playerShipModel");
//model.name = "playerShipModel";
//model.collider.
model.transform.localEulerAngles = new Vector3(0,0,0); //attributes.initialRotation;
model.transform.localScale = attributes.initialScale;
model.transform.position = new Vector3(0,0,1.0f);
// Trying with transform before and after still doesn't work.
//model.transform.parent = this.transform;
//model.transform.position = new Vector3(0,0,0);
That is my code. I've tried to move the ship via temporary and find before and after I set the transform. The ship wont move at all unless I go directly in and pause the game then move it my self. I don't know why.
Update -- This is weird. I can move it, but I cannot set it's position. I have to add or subtract from it's position.
Update 2 -- Solved. Read answer below.
Answer by twinnuke · May 06, 2013 at 11:56 PM
It seems that due to the way I initialize, I can't actually move the objects until the frame after the init. So I have to do it elsewhere, Somewhere that isn't part of any start function even if it's delegated.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to compare and detect overlapping gameObject Prefabs using maths 0 Answers
Make multiple Projectiles move at the same Time... 0 Answers
Instantiate rigidbody C# 1 Answer