- Home /
NullReferenceException: Object reference not set to an instance of an object
hi guys, i am totally new in unity 3D and i am following this tutorial http://youtu.be/HzTceINFowY?t=15m47s, but the guy uses javaScript and i have some c backgraund and i want use c# instead(i've never programed in c# before)
unity3D give me this error
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.AddComponentWindow.get_className () (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/Inspector/AddComponentWindow.cs:300)
UnityEditor.AddComponentWindow+NewScriptElement.OnGUI () (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/Inspector/AddComponentWindow.cs:97)
UnityEditor.AddComponentWindow.ListGUI (.Element[] tree, Single anim, UnityEditor.GroupElement parent, UnityEditor.GroupElement grandParent) (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/Inspector/AddComponentWindow.cs:756)
UnityEditor.AddComponentWindow.OnGUI () (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/Inspector/AddComponentWindow.cs:525)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/84669f285f6a667f/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/84669f285f6a667f/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Applications/buildAgent/work/84669f285f6a667f/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/GUI/DockArea.cs:234)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/GUI/DockArea.cs:227)
UnityEditor.HostView.OnGUI () (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/GUI/DockArea.cs:120)
here is the code using UnityEngine; using System.Collections;
public class MeleeSystem : MonoBehaviour
{
public int TheDamage = 50;
public float Distance;
/*// Use this for initialization
void Start () {
}*/
// Update is called once per frame
void Update ()
{
Vector3 fwd = transform.forward; //transform.TransformDirection(Vector3.forward)
RaycastHit hit;
if (Input.GetButtonDown("Fire1"))
{
//RaycastHit hit = new RaycastHit();
//if (Physics.Raycast(transform.position, transform.InverseTransformDirection(Vector3.forward), hit) ) {
if (Physics.Raycast(transform.position, fwd,out hit))
{
Distance = hit.distance;
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
thanks.
Comment
This script compiles fine for me. Note I don't see any errors here that relate to the above script.
i don't what happened, i've just refresh the script (CTRL-R) and it seen to work fine now. sorry for the nuisance i feel like a idiot.