Hello,
I’m made a Bomberman but I have a little problem with my script collision detection. My script detects the boxes without coroutine, so that when I put my coroutine it no longer detects the boxes … Would you please solution.
using UnityEngine;
using System.Collections;
public class DestroyCube : MonoBehaviour {
public BoxCollider box1;
public BoxCollider box2;
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.name == "Cube")
{
Debug.Log ("Destroy Cube");
Destroy(collision.gameObject, 4);
}
else if(collision.gameObject.name == "Capsule")
{
Debug.Log ("Destroy Capsule");
Destroy(collision.gameObject, 4);
}
}
IEnumerator Start () {
yield return new WaitForSeconds (4);
box1 = gameObject.AddComponent<BoxCollider>();
box2 = gameObject.AddComponent<BoxCollider>();
box1.size = new Vector3 (0.1f,3,6);
box2.size = new Vector3 (6,3,0.1f);
}
}
thanks you in advance.