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 Aldwoni_legacy · Mar 11, 2011 at 09:37 AM · nullreferenceexception

Object reference not set to an instance of an object?

Hello,

I get this error but can't find a solution.

NullReferenceException: Object reference not set to an instance of an object UnityEngine.GUI.DrawTexture (Rect position, UnityEngine.Texture image, ScaleMode scaleMode, Boolean alphaBlend, Single imageAspect) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/GUI.cs:119) UnityEngine.GUI.DrawTexture (Rect position, UnityEngine.Texture image) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/GUI.cs:116) Scoreteller.Score () (at Assets/Scripts/Scoreteller.cs:64) Scoreteller.Update () (at Assets/Scripts/Scoreteller.cs:92)

using UnityEngine; using System.Collections;

public class Scoreteller : MonoBehaviour { public Texture2D score0; public Texture2D score1; public Texture2D score2; public Texture2D score3; public Texture2D score4; public Texture2D score5; public Texture2D score6; public Texture2D score7; public Texture2D score8; public Texture2D score9; private Rect score1tientallenRect; private Rect score1eenhedenRect; private Rect score2tientallenRect; private Rect score2eenhedenRect; string reactie; // Use this for initialization void Start () { score1tientallenRect = new Rect(Screen.width*0.17f, Screen.height*0.08f,Screen.width 0.04f,Screen.height*0.08f); score1eenhedenRect = new Rect(Screen.width*0.21f, Screen.height*0.08f,Screen.width 0.04f,Screen.height*0.08f); score2tientallenRect = new Rect(Screen.width*0.74f, Screen.height*0.08f,Screen.width 0.04f,Screen.height*0.08f); score2eenhedenRect = new Rect(Screen.width*0.78f, Screen.height*0.08f,Screen.width 0.04f,Screen.height*0.08f); } public void Score() { for(int j=0;j<Quiz.Spelers.Count;j++) { string scorestring = Quiz.Spelers[j].Score.ToString(); if(scorestring.Length == 1) { scorestring = "0"+scorestring; } for(int i=0;i<scorestring.Length;i++) { int test = int.Parse(scorestring[i].ToString()); Rect testRect; if(j==0) { if(i==0) { testRect = score1tientallenRect; } else { testRect = score1eenhedenRect; } } else { if(i==0) { testRect = score2tientallenRect; } else { testRect = score2eenhedenRect; } } switch (test) { case 0: GUI.DrawTexture(testRect, score0); break; case 1: GUI.DrawTexture(testRect, score1); break; case 2: GUI.DrawTexture(testRect, score2); break; case 3: GUI.DrawTexture(testRect, score3); break; case 4: GUI.DrawTexture(testRect, score4); break; case 5: GUI.DrawTexture(testRect, score5); break; case 6: GUI.DrawTexture(testRect, score6); break; case 7: GUI.DrawTexture(testRect, score7); break; case 8: GUI.DrawTexture(testRect, score8); break; case 9: GUI.DrawTexture(testRect, score9); break; default: reactie = "Er is iets fout gegaan "; break; } } } } // Update is called once per frame void Update () { Score(); } }

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

1 Reply

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

Answer by loopyllama · Mar 11, 2011 at 10:20 AM

You are calling GUI.DrawTexture which requires it to be in an OnGUI() function. Check out the docs here: http://unity3d.com/support/documentation/Components/gui-Basics.html

Fix the whole thing by adding a:

void OnGUI() { //and cut paste your entire switch statement here }

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 Aldwoni_legacy · Mar 11, 2011 at 10:24 AM 0
Share

I changed Update to OnGUI, thanks

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

No one has followed this question yet.

Related Questions

How do I resize the Lightmap Array via Editor Script? 1 Answer

How can this possibly be null? 2 Answers

NullReferenceException After A Few Hours? 1 Answer

Object reference not set to an instace of an object (JS) 0 Answers

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