|
Ok, I know the first admin to see this will think "This has been asked before! ~delete~" but I just don't understand! The other instances where this has been asked seems to be quite specific to their needs. Rather than saying "This is my code, make it do this" can someone please explain to me, using a random piece of code, how to call a variable from another script? If you do need to see my script I'll put it on but I'd prefer to learn this rather than copy it :) Thanks.
(comments are locked)
|
|
JS: C#: ...and look at the Unity manual from There are a lot of other good sections that are buried 6 links down from somewhere -- you just have to use a combination of the links in Unity combined with Google and be prepared to bookmark.
Jul 15 '12 at 03:35 PM
Owen Reynolds
Ok, I think I get it but I'm returning an error on this: Any ideas (i have a script named "HealthBar" with a variable "stamina" in it and its attached to the same object as this script) - Thanks for your answers as well! Edit: error says: "The type or namespace name `HealthBar' could not be found. Are you missing a using directive or an assembly reference?"
Jul 15 '12 at 09:33 PM
venhip
No, its C#, and I'm sure it is. The variable in the other script is java but ^ this one is in C# because its a modified script from somewhere else. Thanks.
Jul 15 '12 at 09:48 PM
venhip
well if that's in JS it should be Just make sure you stamina variable is accessible.
Jul 15 '12 at 09:44 PM
trickpirata
In C#: Just make sure that the healthbar is attached with the current gameObject that your workin on.
Jul 15 '12 at 09:51 PM
trickpirata
Sorry to be the bearer of bad news. It's a total killer - you really should stick with one language - makes life a lot easier.
Jul 16 '12 at 11:36 PM
whydoidoit
(comments are locked)
|
|
I'm fairly certain if you declare the variable as "Public Static (Type) (VariableName)", it should be accessible outside of the script by using "ScriptName.VariableName". But note that declaring it as static means there will only be 1 of that variable, so you don't want to use it for something that multiple objects have, like an enemy's health.
(comments are locked)
|
