I’m trying to use collision detection to find matching tag names. I use leap motion to grab an object and place it in a basket. I then grab another object with the same tag and place it in the same basket. If the tags match, I add +1 to the score and destroy the objects.
For some reason my code doesn’t increment for each new pair.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class DetectPair : MonoBehaviour {
public Text countText;
private string parentTag;
private int count;
//string tags = new string[2];
void Start(){
count = 0;
SetCountText ();
}
void OnCollisionEnter(Collision other) {
//other.gameObject.tag = tags [0];
parentTag = transform.tag;
if (other.gameObject.tag == parentTag) {
Debug.Log ("Match Detected");
Destroy (gameObject);
Destroy (other.gameObject);
//gameObject.SetActive(false);
//other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
} else {
Debug.Log ("Match not Detected");
}
}
void SetCountText () {
countText.text = "Pairs Matched: " + count.ToString ();
}
}