I'm building an app where the user can customize bicycles on an iPad.. Currently I'm working on switching bicycle components based on a GUI touch.
I'm able to instantiate prefabs in the correct postion since I add them as a child to the bicycle gameObject, so if the user rotates the bicycle and adds a new gameObject it will update the position of where it needs to be instantiated.
The problem I have encountered is that the first time I instantiate a prefab, it is not added as a child, and has the Vector3(0,0,0). Instantiating the second time however the prefab is in the correct position, rotation and is added as a child to the bicycle gameObject... I'm really not sure what's going on here. Has anyone else encountered a similar problem? Possibly I'm overlooking something in my script?
since clone is a "permanent" var, the line "clone = instantiate..." sets it to the instantiation, but since your other commands are BEFORE this, it was simply null (since at this point "clone" does not exist inside the scene).. then the next time you tap, the data is applied to the object previously instantiated. (And immediately re-instantiated at the new position..)
also, is "clone = instantiate(clone..." intended? usually it would be a separate var, like:
var newClone = Instantiate(clone...
where clone is a reference to the prefab being instanced. In your code, you are replacing the var with it's copy.. not necessarily an issue though, I suppose..
Updated code thanks to Seth Bergman:
answered Jul 19 '12 at 02:33 PM