- Home /
Using a top level variable in a class
Hey,
I have a problem with using a variable that I declared outside the class, in a class. I already have spent hours searching for an answer on the forum, but didn't find anything. If I try this, Unity acts as if the variable doesn't exist. Here is my code (I simplified it):
#pragma strict
var chunkWidth=49;
class Chunk{
var width:short;
var position:Vector3;
function Chunk(pos:Vector3){
this.width=chunkWidth; //this gives the error: Unknown identifier: 'chunkWidth'.
this.position=pos;
}
}
This error also occurs when I want to use a function within the class.
You can't use chunkWidth directly because it's not static. Use C# and you'll get a more useful error. http://blogs.msdn.com/b/oldnewthing/archive/2006/08/01/685248.aspx
But what if I would like to use a function in my class? (like Instantiate)
Your answer
Follow this Question
Related Questions
Attach a value to an instantiate object and call it in the class of this object 0 Answers
Loading Prefab from Script 1 Answer
Setting the variable on a GameObject to be instantiated (not yet existent) cs and js 2 Answers
How to bind different type of data in an array ? 1 Answer
How to access a variable from a game object once instantiated (C#) 1 Answer