Hello there, i need to destroy my gameobject when i click that object. The following code is working fine, but i want to destroy the objects with some particular distance. Which means if my object is far i need to go close and click that object.
using UnityEngine;
using System.Collections;
public class Capture : MonoBehaviour
{
RaycastHit Weapon_Hit;
public int Rat, Frog, Snake;
void Start()
{
Rat = 0;
Frog = 0;
Snake = 0;
}
void Update()
{
if (Input.GetButton ("Fire1"))
{
if (Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out Weapon_Hit))
{
if (Weapon_Hit.collider.tag == "Rat")
{
Rat = Rat + 1;
Debug.Log ("Rat: " + Rat);
GameObject.Find("Rat_Count_Text").guiText.text = " " + Rat;
Destroy(Weapon_Hit.transform.gameObject);
}
if (Weapon_Hit.collider.tag == "Frog")
{
Frog = Frog + 1;
Debug.Log ("Frog: " + Frog);
GameObject.Find("Frog_Count_Text").guiText.text = " " + Frog;
Destroy(Weapon_Hit.transform.gameObject);
}
}
}
}
}
-Prasanna