Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by softword · Jul 10, 2013 at 05:35 AM · c#c#-and-js

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
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Jul 10, 2013 at 05:53 AM 0
Share

This script compiles fine for me. Note I don't see any errors here that relate to the above script.

avatar image softword · Jul 10, 2013 at 06:58 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xtremepman · Jul 10, 2013 at 06:08 AM

You need to set the variable values

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

Make C# Class Globally Available on JavaScript 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges