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 idohadar111 · Mar 24, 2017 at 11:40 AM · image loader

NullReferenceException: Object reference not set to an instance of an object [Please Help]

The Error happendes when the "Day2" method is activated

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 public class TextController : MonoBehaviour {
     
     
     public Text text;
     public Image imageGO;
     float timeLeft = 3.5f;
 
     private enum States {backstory, cell_1, scout_1, scout_2, talk_1, sleep_1, lock_1, blood_1};
     private States myState;
     
     void Start () {
         myState = States.backstory;
     }
     
     void Update () {    
     if (myState == States.backstory) {
         state_backstory();
     }else if (myState == States.cell_1) {
         state_cell_1();
     }else if (myState == States.sleep_1) {
         state_sleep_1();
     }else if (myState == States.talk_1) {
         state_talk_1();
     }else if (myState == States.scout_1) {
         timeLeft -= Time.deltaTime;
           if(timeLeft < 0) {
         myState = States.scout_2;
     }    
         state_scout_1();
     }else if (myState == States.scout_2) {
         state_scout_2();
     }else if (myState == States.lock_1) {
         state_lock_1();
     }else if (myState == States.blood_1) {
         state_blood_1();
     }
  }
   
     void state_backstory () {
         text.text="You wake up in an odd bed, you quickly realize that you are in a prison cell." +
                   "You try to remember what you did that caused your arrest. But you could not recall a thing." +
                   "You try to remember who you even are, but you couldn’t, no matter how hard you tried.\n\n" +
                   "Press Enter to continue";
         if (Input.GetKeyDown(KeyCode.Return)){
            myState = States.cell_1;
         }
     }
     
      void state_cell_1 () {
         text.text="You hear people whom you assume are guards outside the room. what will you do?\n\n" +
                   "S.go to sleep, maybe you just need a rest and you’ll remember?\n" +
                   "T.Ask the guards why you’re there\n" + 
                   "V.Scout the room maybe you could find some clues?";
         if (Input.GetKeyDown(KeyCode.S)){
         myState = States.sleep_1;
         }else if (Input.GetKeyDown(KeyCode.T)){
         myState = States.talk_1;
         }else if (Input.GetKeyDown(KeyCode.V)){
         myState = States.scout_1;
         }
     }
     
     void state_sleep_1 () {
         text.text="a day passes...";
         Day_2();
     
     }
     
     void state_talk_1 () {
         text.text="You ask the guards why you’re there.\n" +
                   "They laugh at you… it seems this isn’t going anywhere.\n" +
                   "The guards leave, now that you’re on your own, What should you do?";
                   
         if (Input.GetKeyDown(KeyCode.V)) {
         myState = States.scout_1;
         }else if (Input.GetKeyDown(KeyCode.L)) {
         myState = States.lock_1;
         }
 
     
     }
     
     void state_scout_1 () {
         text.text="You look around the room…\n";
     }
     
     void state_scout_2 () {
         text.text="you see some writing on the wall:”It never ends” and some scratches counting up to 20";
         
         if (Input.GetKeyDown(KeyCode.V)) {
             myState = States.blood_1;
         }else if (Input.GetKeyDown(KeyCode.S)) {
             myState = States.scout_1;
         }
     }
     
     void state_lock_1 () {
     
     }
     
     void state_blood_1 () {
         text.text="111";
     }
     
      void Day_2() {
         imageGO.sprite = Resources.Load<Sprite> ("DayCounter13");
     }
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Chefsu · Mar 24, 2017 at 12:19 PM

 public Image imageGO;

Did you assign an Image to this field in the editor? If that didn't do it, check if the name of the sprite is the same as in your Resources folder.

 imageGO.sprite = Resources.Load<Sprite> ("DayCounter13");

If that didn't do it, check if you set the Texture Type in the inspector to: Sprite (2D and UI) alt text


I hope this helped you out. If all above didn't work, click on the error and select everything that pops up beneath the console lines and paste it here.


1bc8d1f992b8e3093d263784877da94a.png (3.6 kB)
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
avatar image
0

Answer by idohadar111 · Mar 24, 2017 at 12:32 PM

NullReferenceException: Object reference not set to an instance of an object TextController.Day_2 () (at Assets/Scripts/TextController.cs:109) TextController.state_sleep_1 () (at Assets/Scripts/TextController.cs:68) TextController.Update () (at Assets/Scripts/TextController.cs:24)

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 Chefsu · Mar 24, 2017 at 12:58 PM 0
Share

There is nothing wrong with your code, the problem should be one of the things i said before.

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

97 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 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

Png's won't show when trying to apply them to a image 0 Answers

Load an image from https URL with login 0 Answers

How to add a picture 0 Answers

How to load random images from a stock image website into unity? 0 Answers

How to load random images from a stock image website into unity? 1 Answer


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