I made a script for my game, it basically allows you to “Harvest” whatever you put the script on and “drops” what you put into an ItemDrop transform. this is the script
#pragma strict
var itemdrop : Transform;
function Update ()
{
if(Input.GetMouseButtonDown)
Destroy (gameObject, 5);
Instantiate(itemdrop, transform.position, Quaternion.identity);
}
My only problem is due to the Input.GetMouseButtonDown, the prefab destroys itself as soon as i click play. I need it to only destroy itself when i am in range of it. How would i go about doing this? I would try RayCast but i don’t know how. I prefer Javascript and any help is appreciated