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
1
Question by Bruno999 · Dec 19, 2012 at 07:52 PM · objectreferenceinstancenotset

NullReferenceException:"Object reference not set to an instance object"

Hello everyone, I´m new in unity 3d so I was making a very very fps(Thanks to ETeeskiTutorials). So I attach a "MouseLookScript" to the main camera and It´s work. Well, then I create a capsule and I use it as "PlayerCapsule". Next I Attach the main camera to the PlayerCapsule so the main camera follow the "player". Well, when i want to test the "game"xD Its says NullReferenceException:"Object reference not set to an instance object"

I dont know what is happening, here i give us the scripts that i use:

MouseLookScript:

 var LookSensitivity : float = 5;
 @HideInInspector
 var yRotation : float;
 @HideInInspector
 var xRotation : float;
 @HideInInspector
 var currentYRotation : float;
 @HideInInspector
 var currentXRotation : float;
 @HideInInspector
 var yRotationV : float;
 @HideInInspector
 var xRotationV : float;
 var LookSmoothDump : float = 0.1;
 
 function Update () 
 {
     yRotation += Input.GetAxis("Mouse X") * LookSensitivity;
     xRotation -= Input.GetAxis("Mouse Y") * LookSensitivity;
     
     xRotation = Mathf.Clamp(xRotation, -90, 90);
     
     currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, LookSmoothDump);
     currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, LookSmoothDump);
     
     transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
 }

PlayerMovementScript:

var walkAcceleration : float = 5;

var cameraObject : GameObject;

 function Update () 
 {
     transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentyRotation, 0);
     rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
 }
Comment
Add comment · Show 3
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 Dave-Carlile · Dec 19, 2012 at 08:23 PM 0
Share

Which line of code does the error happen on? The Unity editor should tell you this. We need to know too in order to help.

avatar image Bruno999 · Dec 19, 2012 at 11:39 PM 0
Share

I fix it, thanks to cagezero, but i have another problem, its says Input Axis X is not setup, i know i have to go to edit, project settings, input but i dont know how to set up, and also i thinks Axis Y is not set up, thanks for reading

avatar image Dave-Carlile · Dec 19, 2012 at 11:52 PM 0
Share

You should mark cagezero's answer as accepted then. And if you hvae a new question you should post a new question.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by cagezero · Dec 19, 2012 at 09:11 PM

Change:

transform.rotation = Quaternion.Euler(0,cameraObject.GetComponent(MouseLookScript).currentyRotation, 0);

To:

transform.rotation = Quaternion.Euler(0,cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);

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

11 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

Related Questions

Object reference not working 0 Answers

Object Refererence not set yada yada... 2 Answers

Object reference not set to an instance of an object. 0 Answers

NullReferenceException was thrown. Object reference not set to an instance of an object. 1 Answer

Object reference not set to an instance of an object 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