- Home /
Rotating a clone on Instantiation
I've got a prefab 'girl1' and I can instantiate a clone of the prefab in a certain position where it is later destroyed.
The prefab is then instantiated again, but in a different position, and so on quite a few times.
On the first instantiation, the clone is in the correct position, and the clones are also in the correct location on subsequent instantiation.
My problem is this, on subsequent instantiations, as well as being in the correct location I also want to rotate the clone.
I know how to locate the clone, but how do I also rotate it.
The bit of code where I destroy the previous clone and instantiate another one is as follows, and it all works Ok except for rotation:
Destroy (GameObject.Find("girl1(Clone)"));
Instantiate (girl1, Vector3 (30,177.3223,2.542483),Quaternion.identity);
What do I need to add to change the rotation, for example to 90, 180, 0, ?
Answer by Eric5h5 · Aug 06, 2010 at 05:13 PM
Use Quaternion.Euler:
Instantiate(girl1, Vector3(30, 177.3223, 2.542483), Quaternion.Euler(90, 180, 0));
Answer by spinaljack · Aug 06, 2010 at 04:51 PM
var rotation : Quaternion = Quaternion.identity; rotation.eulerAnlges = Vector3(90,180,0);
Instantiate(girl1, Vector3 (30,177.3223,2.542483),rotation);
Excellent. Wotks a treat. Thanks very much spinaljack. $$anonymous$$uch appreciated.
Your answer
Follow this Question
Related Questions
scripts gets disabled when the prefab is instantiated 1 Answer
Cloning Objects with Instantiate() - variables/references for added Components not stored? 3 Answers
Instantiated Object's Scripts not enabled? Not sure why 3 Answers
Instantiate Reference Problem 1 Answer
How to remove the (Clone) from instantiated prefab C# 2 Answers