- Home /
Problem with collecting plants
i made a little script that i attached to my 3d person camera but it wont work it only works with that 1 prefab plant in the scene or when i copy that plant from the scene all plants disappear at once help i cant figure it out :(
var PlantPos :Transform; // The var will hold the pos of the camera
var dist; // the var will hold the distance between the 2 objects
var Plant :GameObject; // the var where the gameobject will be saved
function Update () { // updates every frame;
if (PlantPos) {
var dist = Vector3.Distance(PlantPos.position,transform.position);
print ("Distance to the Plant:" + dist);
if(dist<=3 && Input.GetKeyDown("e")) // if the distance is lower then 3 then the plant will get
//deleted if the user presses e
Destroy(Plant); //destroys the object
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
beginner programming woe grids 1 Answer
open a link inside unity 2 Answers
Prefab is not working anymore after opening my project. 3 Answers
Toggle map/Camera [JS] 1 Answer