- Home /
The name "Destory" Does not exist in the current context
Hey, so I am trying ot make a woodcutting script and I have this script but when I try and fix it it comes up with The name "Destory" Does not exist in the current context. Can anyone help me?
Code:
[code]using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TreeHealth : MonoBehaviour {
public int health = 100;
private void Update()
{
if (health <= 0)
{
Destory(gameObject);
}
}
} [/code]
Answer by efeguclu · Jul 04, 2017 at 02:20 PM
you have to use Destroy(gameObject); not Destory..
;)
I cannot believe this was my problem. For anyone still getting issues, try UnityEngine.Object.Destroy(gameobject);
Well, UnityEngine.Object.
isn't required in almost all cases since you usually are inside a $$anonymous$$onoBehaviour or ScriptableObject derived class so you have direct access to everything defined in UnityEngine.Object. When you said this was your problem, do you mean you also had two swapped characters (due to too fast typing)? Or do you mean you were missing the UnityEngine.Object?
Answer by Epsilon_Delta · Dec 10, 2019 at 08:04 PM
Either you have a typo or you are not in the right namespace. If the latter is the case, try putting using UnityEngine
in front of your class
This question is over 2 years old. Also the error is pretty obvious. You can read it already in the title, in the error message he copied as well as in his code. Destory != Destroy
In case you still don't see it De-sto-ry
and De-stroy
are two different things.
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
GameObject.FindGameObjectsWithTag still finding destroyed object (C#) 1 Answer
Calling an Audio Source on one game object from a script on another game object..? 1 Answer
Cannot destroy Component while GameObject is being activated or deactivated 2 Answers
Particle system not destroying. 3 Answers