I want a cube to be destroyed when i click it,but my script has these following problems.
1-The cubes it is attached to(2) destroy all at a time.
2-It gets destroyed when i click anywhere not only when it is on top of the cube.
I have 2 different codes,let me post them both.
using UnityEngine;
using System.Collections;
public class checkifclick : MonoBehaviour {
public int points = 0;
void OnMouseDown () {
Destroy(gameObject);
points = points + 1;
}
void Update() {
Debug.Log (points);
}
}
using UnityEngine;
using System.Collections;
public class checkifclick2 : MonoBehaviour {
public static int points = 0;
void Update() {
if (Input.GetMouseButtonDown(0)) {
points = points + 1;
Destroy (gameObject);
}
Debug.Log (points);
}
}