- Home /
transform.rotation problem
Before I begin I will post my code first so you can see what's going on....
if (Input.GetKey("a")) { var launchPos1 = launchSites[(Random.Range(0,launchSites.length))].transform.position; Instantiate (firework, launchPos1, Quaternion.identity); }
Now what I want to do is to be able to factor in the rotation element of the empty gameobject that this part of the script is attached to, however, when I try :-
var launchRot1 = launchSites[(Random.Range(0,launchSites.length))].transform.Rotate; Instantiate (firework, launchPos1, launchRot1);
I get an error come up saying that "No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.Vector3, function (UnityEngine.Vector3): void)' was found (BCE0023)
I have tried transform.rotation as well and been told that it doesn't exist.
The code works perfectly without it, but I'd like to be able to add it it in if it's possible.
Answer by Seth-Bergman · Nov 08, 2012 at 06:14 PM
you must have messed something up when you tried transform.rotation, it works:
http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html
why not just set both from the same Transform:
if (Input.GetKeyDown("a")) {
var launchSite : Transform = launchSites[Random.Range(0,launchSites.length)].GetComponent(Transform);
Instantiate (firework, launchSite.position, launchSite.rotation);
}
Worked perfectly fine thank you, Such a simple thing that need to be done :p