- Home /
C# Accessing Variables from Class Variable
Hi everyone, I have a class variable and I 'm trying to access the variables it inherits from.
class variable
public someClass[] someClassArray;
class it inherits from
using UnityEngine;
using System.Collections;
public class someClass : MonoBehaviour {
public string someString;
public bool someBool;
public int someInt;
public float someFloat;
}
So in theory I should be able to access the variables by typing in
someClassArray[0].
But when I type it in I don't see the variables I put into the class. How do you access those variables?
Answer by robertbu · Jun 08, 2013 at 01:00 AM
You are not inheriting anything here. You have a array of references to objects of type 'someClass'...and unless you initialize the array in the Inspector, you will have an uninitialized array that will generate a null reference exception the first time you try and use it. To access the variables you put into the class, you need an array index. Try typing:
someClassArray[0].
$$anonymous$$y bad, I made a mistake while typing this up. I changed someClassArray. to someClassArray[0]. . I still can't find the variables in the class.
$$anonymous$$ake sure the rest of your script compiles. I tested it, and it worked fine for me. Go one character further and type the 's'.
Your answer
Follow this Question
Related Questions
C# Unity 3d Don't Destroy Class On Load 1 Answer
C# Declaring Variables Within If Statements 2 Answers
How to execute a Skript global? 2 Answers
Saving final score and displaying on main menu 1 Answer
null texture passed to GUI.DrawTexture 0 Answers