- Home /
This question was
closed Apr 07, 2013 at 06:59 AM by
AlucardJay for the following reason:
Duplicate Question : http://answers.unity3d.com/questions/432975/object-reference-not-set-to-an-instance-of-an-obje-24.html
Question by
turbinator · Apr 07, 2013 at 01:49 AM ·
objecttag
help with game error
I dont know what i am doing wrong? I get an error when running the game and when i cut down a tree i get ""NullReferenceException: Object reference not set to an instance of an object cutTree.Update ()""
This is my code: var trees: GameObject[]; var bullitPrefab:Transform;
function Start() {
trees = GameObject.FindGameObjectsWithTag("Tree");
}
function Update()
{
if(Input.GetButton("placeLog")) {
for(var tree in trees) {
if(tree == null)
continue;
if(Vector3.Distance(tree.transform.position, transform.position) < 5)
{
Instantiate(bullitPrefab, GameObject.Find("logSpawn").transform.position, Quaternion.Identity);
Destroy(tree);
break;
}
}
}
}
could i have some help please
Comment
Follow this Question
Related Questions
changing objects color through a raycast? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Destroy only selected object 1 Answer
Footstep Script Not Working 2 Answers