Combine two game objects destroy them and create a new one
Hello everybody,
I'm new to Unity and have the following problem:
I'm trying to develop an idle game in which two characters can be combined and a better character appears. You know the game principle.
How do I write this as code that two game objects can be combined and destroyed and the better figure appears in the same position?
public GameObject GO1;
public GameObject GO2;
private Vector3 oldPos;
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject)
{
Vector3 oldPos = transform.position;
Destroy(collision.gameObject);
Instantiate(GO2, oldPos , Quaternion.identity);
}
}
Thanks for the help and greetings from Germany
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613010209im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enemy Spawner Help 0 Answers
Delete object and spawn another 3 Answers
How to identify players on Photon Unity? 2 Answers
Bullet spawning at high Player speed 1 Answer
NetworkServer is not active. Cannot spawn objects without an active server. 0 Answers