Hi, im a new game developer, and i have a problem, i spawn 5 prefabs, but when i touch 1 object to destroy, 4 object are be destroyed ! Now i want to touch 2 object, this 2 object will be destroy, not 5, that all i need.
Tks for read, here my code:
void Update () {
if (Input.GetMouseButtonDown (0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
Destroy(hit.collider.gameObject);
}
}
}
private GameObject harmonyVideo;
// Use this for initialization
void Start () {
harmonyVideo = GameObject.Find("HarmonyVideo");
}
// Update is called once per frame
void Update()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
Ray ray;
RaycastHit hit;
ray = Camera.main.ScreenPointToRay(touch.position);
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (hit.transform.gameObject.name == ("HarmonyVideo"))
{
Destory(gameObject, 0.2f);
}
else
{
Debug.Log("This object is not the Harmony Video");
}
}
}
}
}