- Home /
how to: make global variable
hi, i am newbie in unity. before i use vb.net. in vb.net we can create a module just for containing our global variables that can be used in all forms. can i achieve that feature in unity?
the real problem is : i have import some sprites in "assests/resources". i have used them in making sprite in the scene. but i need the "sprite" game object to return some value from comparing its sprite with the sprites in "assets/resources". anyone can help?
i think your variable should be static to get effect from other scripts :)
There's nothing that you can do in vb.net that you can't do in Unity if you can program in C# or Javascript!
You are not explaining your problem well. For instance, with the function:
gameobject.GetInstanceID
...you can get the instance id of a GameObject, and is always guaranteed to be unique. However, it may not be useful in your case, because you can't use it to compare with anything in assets/resources.
So, why exactly do you want to compare a GameObject instance, with something in assets/resources?
all right, i just use array to contain all my sprite in resources folder. and have done the advice from Qasem2014. thx alot.
NB: i just try to make candy-crush-like game to start my "game developer career" :)
Answer by Grim_Darknight · Dec 13, 2014 at 09:29 PM
I don't know what specific variable you are dealing with but I will use an integer as an example called number.
using .....
Class xxxx : Monobehavior
{
public static int number = 0;
Awake()
{}
}
Answer by Ericool · Dec 14, 2014 at 01:49 AM
make a script for example SpriteMgr :
inside put a getter like that :
public Sprite[] instance{get;private set;}
then from another class just get an instance of that script like that : private SpriteMgr spriteReference = new SpriteMgr();
private void Awake(){ if( blabla == spriteReference.instance.something){ do something...
} }
Your answer
Follow this Question
Related Questions
Accessing 4.6 GUI build-in sprites in C# 0 Answers
Loading Addressable Sprites using their Address 0 Answers
Sprite obstruction transparent area 1 Answer
How do I change the draw rectangle of a sprite? 0 Answers
Resources.Load("sprite") returning nil 0 Answers