|
i want to swap objects using instantiate. im having trouble using instantiate, could someone help me with the code.
greetz,
(comments are locked)
|
|
When you instantiate with just a prefab it'll appear at the location that you saved it in (could be anywhere). When you use transform.parent it changes the parenting of the object but it wont move to where the old object was. What you need to do is instantiate the new object at the same transform.position (or alter it's position afterwards, which ever you prefer). At the moment I'm assuming your old object gets destroyed and then you can't find the new object because it appeared else where. Do something like this: i tried this code but do i need to create some new variables. ??? cuz im getting some errors?
Jun 15 '10 at 11:24 PM
ab_cee
Yes, you need to add your own header with all the variables declared. objPrefab is type GameObject where you drag the prefab onto in the spector. oldObj is the thing you're replacing.
Jun 16 '10 at 03:00 AM
spinaljack
(comments are locked)
|

What is the outcome of your code? Where is oldObj defined? Does oldObj has a parent?
the old obj is in the gamescene and needs te be destroyed completely: the parent with children etc. and a new object needs te be exactly in the same spot where the old object was