- Home /
 
 
               Question by 
               UDN_23370f8a-d454-441c-815a-b70d1942ad47 · Feb 10, 2019 at 02:21 PM · 
                collisionspawnspritescollider2dspawning problems  
              
 
              Spawn gap in unity?
I am currently creating an endless runner type of game where two objects(good and bad) are getting spawned from three spawn points randomly at different times. The problem i am encountering is that two objects spawn together sometimes. I tried to make a script that destroys one of the objects if they collide together, but it did not work. Check attached screenshots and the script.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Grouping : MonoBehaviour
 {    
 
     private void OnCollisionEnter2D(Collision2D col)
     {
         if(gameObject.tag == "Enemy")
         {
             Destroy(gameObject); 
             Debug.Log("success");
         }
     }
     
 }
 
               

 
                 
                unitysc2.png 
                (304.8 kB) 
               
 
                
                 
                unitysc1.png 
                (344.1 kB) 
               
 
              
               Comment
              
 
               
              Your answer