hello guys…I am working on my first 2d unity game and I am stuck. The problem is:
The ball is rolling down. I have created an empty game object and attached a box collider to it and the Trigger is on. I want to destroy the game objects as they exit the trigger and spawn new objects. however I have written the code. It is working but not all the game objects are getting destroyed some are remaining as it is even if they exit the trigger.
code:
using UnityEngine;
using System.Collections;
using System;
public class BoxCollControl : MonoBehaviour {
public GameObject player;
private Vector3 pos;
private Collider2D cor;
//private woodManager wd;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
pos = player.transform.position;
pos.z = -1;
pos.x += 0;
gameObject.transform.position = pos;
}
void OnTriggerExit2D(Collider2D other){
if (other.tag == "path" || other.tag == "stopper") {
Debug.Log ("Hiiiiii");
cor = other;
GameObject.Destroy(cor.gameObject);
woodManager.Instance.Spawnwood();
}
}
}
so please guys help me so that I can continue…
thank you
