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 Rgalaxy · Jan 14, 2014 at 08:24 PM · javascripterrornullreferenceexception

NullReferenceException

i really don't understand why this error come to me so much times x.x i could handle it 2-3 times, but now i can't handle it again.. although i have build the exact same code with the last one..

so my code is guiSchool3.js (This script attached to Main Camera on Scene "A")

 #pragma strict
 var script : guiSchool2;
 var choice : int;
 script = GetComponent(guiSchool2);
 choice = script.flag;
 
 var tekstur1 : Texture;
 function Start () {
     
         
 }
 function OnGUI(){
     
     if(choice==1){    
         GUI.DrawTexture(Rect(Screen.width*0.125,Screen.height*0.125,Screen.width*0.75,Screen.height*0.75),tekstur1);
     }
     else if (choice==2){
         
     }
 }

and here's guiSchool2! (i delete the part that not linked by the error)(This Script attached to Main Camera on Scene "B")

 #pragma strict
 
 var flag: int;
 
 function OnGUI (){
 
     GUI.DrawTexture(Rect(posbg_w,posbg_h,bg_w,bg_h),bg);
     if(GUI.Button(Rect(pos_b1w,pos_b1h,b_width,b_height)," ",button_perkalian)){
         flag = 1;
         Application.LoadLevel("School3");
     }
     if(GUI.Button(Rect(pos_b1w,pos_b2h,b_width,b_height)," ",button_luas)){
         flag = 2;
         Application.LoadLevel("School3");
     }
     if(GUI.Button(Rect(pos_b1w,pos_b3h,b_width,b_height)," ",button_satuan)){
         flag = 3;
         Application.LoadLevel("School3");
     }
 }

and the console throw me this exception

NullReferenceException: Object reference not set to an instance of an object guiSchool3.Main () (at Assets/Scripts/School/guiSchool3.js:5)

i believe i've done the exact same with the code before.. but it's still wrong.. why?

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 Doeko · Jan 14, 2014 at 08:26 PM 0
Share

Please indicate exactly where the error occurs. At line 5 at both scripts it's impossible.

avatar image Rgalaxy · Jan 18, 2014 at 10:43 AM 0
Share

did you even read the error? (at Assets/Scripts/School/guiSchool3.js:5) it is on guiSchool3.js which is the first code..

i still looking for the right answer thou, and still couldn't figure out why its error..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AwesomeFaceHD · Jan 14, 2014 at 10:06 PM

I'm pretty sure you should assign "script" and "choice" in the start function. Unless you already fixed it.

 function Start() {
     script = GetComponent(guiSchool2);
     choice = script.flag;
 }
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 Rgalaxy · Jan 17, 2014 at 03:56 PM 0
Share

i've put it there, but the error still comes out.. i really don't understand why this happens.. maybe another way to solve this?

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

21 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

Related Questions

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

Object reference not set to an instance of an object 1 Answer

Hi I get an error code when i'm using my Javascript and I can't understand how to fix it... :( 1 Answer

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

[js]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