- Home /
Public variable in script different for every game object.
Hello fellow Unity users!
This is actually a request for confirmation. So, if I put a public variable (say, an integer) in a script, and attach that script to two objects and change the variable to a different number for each object the objects have a different value for the public variable although they have the same script. This is normal functionality that I can count on, right? I know it sounds totally elementary but I've never thought that you can choose two different value for a variable in the same script.
I ask because I'm working out the basics for a CCG and if this works, then I can just create all of my card stats as public variables, apply the same script to all the cards, and just change the numbers in the inspector. This works . . . right?
Thanks!
Answer by Graham-Dunnett · Oct 16, 2014 at 07:50 PM
Yes. The script defines a class, and dropping that onto multiple game objects instantiates the class.
If you want the opposite effect (ie one variable that is the same on all versions of a script) then you must declare is as static.