Hi, in my scene i have a car, when its hit by a bullet, the car instantiates a explosion, but then i want to "disappear" the original car, and appear a destroyed car i have in my prefabs, i have no idea where to start, thanks!
You can instantiate the destroyed car with this:
Instantiate(destroyedCarPrefab, originalcar.transform.position, originalcar.transform.rotation);
and destroy the original one like this:
The originalcar is a Gameobject variable filled with the original car gameobject. The destroyedCarPrefab is a Prefab or Gameobject variable filled with the prefab of the destroyed car.
You can instantiate a prefab using Instantiate(prefab, position, rotation).
You can destroy a game object using Destroy(gameObject).
Instantiate(prefab, position, rotation)
In your case, you'd want to instantiate the prefab in the same location and rotation of the old object, and then destroy the old one and the explosion:
GameObject destroyedCarGameObject = (GameObject)Instantiate(destroyedCarPrefab, carGameObject.transform.position, carGameObject.transform.rotation);
See the documentation here:
Just make sure the car prefab and the destroyed car prefab have the same center (pivot) and are facing the same direction when they're rotations are (0,0,0).
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
16 People are following this question.
How to make the other gameObject carry out a function.
Return gameobject from a TriggerEvent.
Changing or replace objects
SOLVED - String replace % with " in C#
Force a RPC to be called on a networkview of another GameObject