- Home /
Problem detection collider with coroutine
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.
Comment
Answer by christoph_r · Jun 01, 2014 at 07:18 PM
Don't make Start a coroutine, instead call all the things you want to set up in another method which you can call with a 4 second delay via Invoke.
Your answer
Follow this Question
Related Questions
collision wont work 1 Answer
Best practice for OnTriggerEnter detection 1 Answer
Collision not working 3 Answers
Transform Object over Players head before destroying 0 Answers