|
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?
(comments are locked)
|
|
try: ... ... 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.. Thank you Seth, this is working really well for me now. I totally overlooked the order of all of my commands which made the "clone" point null. I didn't intend using "clone = instantiate(clone.." for any particular reason, it was the only way that made sense at the time of writing it. Thanks again for all of your help, I'll post the updated code in an answer below.
Jul 19 '12 at 02:29 PM
LANDO
(comments are locked)
|
|
Updated code thanks to Seth Bergman:
(comments are locked)
|
