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 /
This question was closed Feb 18, 2014 at 10:41 AM by Benproductions1 for the following reason:

Duplicate Question

avatar image
0
Question by Mint92 · Feb 18, 2014 at 10:06 AM · c#objectinstanceset

Object Reference not set to an Instance

 using UnityEngine;
 using System.Collections;
 
 public class QuestionClass2 : MonoBehaviour 
 {
     public Question[] arrayOfQuestions;
     public Question currentQuestion;
     public bool showQuestion = true;
     private int coinToss;
     public bool Heads;
     public bool Tails;
     
         
     public class Question
     {
         private string questionText;
         private Rect questionRect;
         
         private string[] answers = new string[4];
         private string[] displayAnswers = new string[4];
         private Rect[] answerRects = new Rect[4];
         
         private string correctAnswer;
         private Rect correctRect;
         
         public int correctAnswerIndex;
         
         private int questionWidth = 300;
         private int answerWidth = 75;
         private int questionHeight = 1000;
         private int correctWidth = 500;
         
         public int selectedAnswer = -1;
         
 
           void Update()
     {    
         //currentQuestion.selectedAnswer = 0;
         
         if(currentQuestion.selectedAnswer == currentQuestion.correctAnswerIndex)                  
     >>>>>>>>> getting an error here{
             ChooseRandomQuestion(); // Picks a random question
         }
     }
 }

Ive attached a script to a empty gameobject, Do i need reference that gameobject ?

Comment
Add comment · Show 4
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 Mint92 · Feb 18, 2014 at 10:13 AM 0
Share

How do I set variable to a component ?

avatar image Mint92 · Feb 18, 2014 at 10:16 AM 0
Share

something like this gameObject.GetComponent().currentQuestion;

avatar image Mint92 · Feb 18, 2014 at 10:40 AM 0
Share
 public QuestionClass2 test = GameObject.FindWithTag("Question$$anonymous$$anager").GetComponent<QuestionClass2>(); 

on this line, i get error Expecting ";", but its there

avatar image Benproductions1 · Feb 18, 2014 at 10:43 AM 0
Share

You can only use compile time values for default variables. This question has been asked many, many times before. I've even answered a couple. I'm sure you can find many of those thorough your preffered search-engine.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Serialization - Variables won't change on original construction 1 Answer

Distribute terrain in zones 3 Answers

Get instance of exisiting object 1 Answer

Object reference not working 0 Answers

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