- Home /
Question by
unity_Kz2LucJRt2wx_w · Mar 15, 2021 at 11:50 PM ·
collisiondestroyspawningdetection
How to delete just one object, both with the same script,How to not delete both objects in a collision?
I am making an RTS and have each planet set up to spawn a unit every 5 seconds, whenever there are 2 or more soldiers meant to be on one tile I aim to converge them into on object, with text below stating the amount of units there. However, the units whenever they touch delete eachother. How do I go about combining these two units?
void OnCollisionEnter (Collision other)
{
if (other.gameObject.CompareTag("Soldier"))
{
counter = other.gameObject.GetComponent<SoldierScripts>().counter += counter;
Destroy(other.gameObject);
}
Debug.Log(counter);
textMeshPro.text = counter.ToString();
Comment
When you select an object to combine set a flag/variable on that object then in the collision script only destroy object with set flag/variable
Your answer
Follow this Question
Related Questions
collision wont work 1 Answer
Create hinge joint 2D by collision 2 Answers
Collision Detection for a Prefab? 3 Answers
Collision Detection not working? 1 Answer