Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by shadobox255 · Sep 05, 2016 at 11:18 PM · error message

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

I keep getting an error stating, NullReferenceException: Object reference not set to an instance of an object opendoor.Update () (at Assets/opendoor.cs:26). I'm using this for my door to open and close it. Can someone tell me what's wrong with this?

 using UnityEngine;
 using System.Collections;
 
 public class opendoor : MonoBehaviour {
 public float doorOpenAngle = 90.0f;
 public float doorCloseAngle = 0.0f;
 public float doorAnimSpeed = 2.0f;
 private Quaternion doorOpen = Quaternion.identity;
 private Quaternion doorClose = Quaternion.identity;
 private Transform playerTrans = null;
 public bool doorStatus = false; //false is close, true is open
 private bool doorGo = false; //for Coroutine, when start only one
 void Start() {
     doorStatus = false; //door is open, maybe change
     //Initialization your quaternions
     doorOpen = Quaternion.Euler (0, doorOpenAngle, 0);
     doorClose = Quaternion.Euler (0, doorCloseAngle, 0);
     //Find only one time your player and get him reference
     playerTrans = GameObject.Find ("Player").transform;
 }
 void Update() {
     //If press F key on keyboard
     if (Input.GetKeyDown(KeyCode.F) && !doorGo) {
         //Calculate distance between player and door
         if (Vector3.Distance(playerTrans.position, this.transform.position) < 5f) {
             if (doorStatus) { //close door
                 StartCoroutine(this.moveDoor(doorClose));
             } else { //open door
                 StartCoroutine(this.moveDoor(doorOpen));
             }
         }
     }
 }
 public IEnumerator moveDoor (Quaternion dest)
 {
     doorGo = true;
     //Check if close/open, if angle less 4 degree, or use another value more 0
     while (Quaternion.Angle (transform.localRotation, dest) > 4.0f) {
         transform.localRotation = Quaternion.Slerp (transform.localRotation, dest, Time.deltaTime * doorAnimSpeed);
         //UPDATE 1: add yield
         yield return null;
     }
     //Change door status
     doorStatus = !doorStatus;
     doorGo = false;
     //UPDATE 1: add yield
     yield return null;
 }

}

Comment
Add comment · Show 1
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 ArturoSR · Sep 06, 2016 at 03:00 AM 0
Share

What is the exact line that the console shows to you?, because, maybe you are not searching using the right method, you can checking it at opening your code file and find that specific line.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Sep 06, 2016 at 03:30 PM

Check this out:
https://docs.unity3d.com/Manual/NullReferenceException.html

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

69 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

UCE0001: ';' expected. Insert a semicolon at the end. 1 Answer

I'm getting the error "(9,35): UCEO001: ';' expected. Insert a semi colon at the end" and I don't know why. P.S. Also how do you "update version" if you're learning with older code? 0 Answers

0xc000007b error on 64 bit machine? 1 Answer

How i do fix this error? Assets/CameraController.cs(17,13): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement,Unity Scripts error 1 Answer

Position is infinite 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