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 triggerdog · Sep 10, 2015 at 06:30 PM · c#unity 5nullreferenceexceptionconsole

Controller gives NullReferenceException and Teleporter is unresponsive when collided

I'm relatively new to the Unity Engine. I'm making a simple game where after the player collects every object in order to reach another scene. However, the teleporter has no response after the player collects every object and collides with the teleporter.

Does anyone know what might have gone wrong with my code? Any help would be appreciated. Thanks. Compiler Error Observation: Console gives a NullReference error everytime the game is running. alt text

alt text

alt text Controller.cs(C#)

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;

 public class Controller : MonoBehaviour {
 public GameObject Ball;
 public float speed;
 public Text countText;
 public Text winText;
 
 private Rigidbody rb;
 private int count = 4;
 
 void Start ()
 {
     rb = GetComponent<Rigidbody>();
     count = 0;
     SetCountText ();
     countText.text = "";
     winText.text = "";
 }
 
 void FixedUpdate ()
 {
     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");
     
     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
     
     rb.AddForce (movement * speed);
 }
 
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag ("Pickup"))
     {
         other.gameObject.SetActive (false);
         count = count + 1;
         SetCountText ();
         //Destroy (other.gameObject);
     }
 }
 
 void SetCountText ()
 {
     countText.text = "Count: " + count.ToString ();
     if (count == 4);
     {
         winText.text = "You Win!";
     }
 }

TeleportPad.cs

      public class TeleportPad : MonoBehaviour {
             
              private GameObject Teleport;
              public Text winText;      
             
              void Start ()
              {
                           winText.text = "";  
              }
       
             
              void OnTriggerEnter(Collider other)
              {
                  if (other.gameObject.CompareTag ("Teleport") &
                   winText.text == "You Win!")
                  {
                      gameObject.SetActive (true);
                      //Destroy (other.gameObject);
                      Application.LoadLevel(2);
                  }
       
              }      
          }  [2]: /storage/temp/54021-uniq.png


uniq4.png (59.2 kB)
uniq5.png (13.5 kB)
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 pako · Sep 14, 2015 at 09:25 AM 0
Share

@triggerdog this is not getting us anywhere. Even if you upload your project and I debug it for you it's not going to help you get very far, because for sure, you will get stuck pretty soon in another part of your project.

In fact, this forum is not a place for getting help with debugging and compiler errors, but some questions do get passed through the forum moderators.

The best thing for you to do in order to learn how to use Unity, as well as general program$$anonymous$$g principles is to explore the Learn section:

http://unity3d.com/learn

avatar image triggerdog pako · Sep 15, 2015 at 05:42 AM 0
Share

Thanks for the link.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Sep 14, 2015 at 07:50 PM

Remove the semicolon from line 48

 if (count == 4)
Comment
Add comment · Show 1 · 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
avatar image triggerdog · Sep 15, 2015 at 05:42 AM 0
Share

Thanks for your help.

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

32 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

Related Questions

Problem referencing an int inside of a dictionary. 0 Answers

Why is my component coming back as null? 1 Answer

Varialbes on prefab script always null 0 Answers

NullRefrenceException - Cant find the cost 1 Answer

NullReferenceException: Object reference not set to an instance of an object, again 2 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