- Home /
Storing Static String into new String variable
I have some ship names defined in my Controller.js script that I'd like to access from other scripts. So in my Controller script I have, for example
static var ship1 : String="Bounty";
In my other script I can use
print ("Ship is "+Controller.ship1);
or print it to my GUI window and it will print "Ship is Bounty" as required. But how can I store this String into another String variable, like so...
var newShip : String;
so I can use i.e
newShip=Controller.ship1;
print ("Ship is "+newShip);
resulting in "Ship is Bounty". As it is it remains blank .e "Ship is .." Appreciate any help on Strings, it's an area I've neglected and now I really need them.
Answer by D_e_l_t_a · Sep 03, 2011 at 08:29 PM
Only one answer and that was spam :(
Anyone have advice on this ? Is it possible to store the Static string into a newer variable, or is there a more refined way to go about this ?
Answer by AaronG · Sep 03, 2011 at 08:44 PM
Just create a new string var and do something along the lines of...
var myString : string;
function Awake() {
myString = CLASSNAMEOFSHIP.ship1;
}
With class name being the name of the class that contains the static string. Though you probably guessed that. :P
Your answer
![](https://koobas.hobune.stream/wayback/20220612201059im_/https://answers.unity.com/themes/thub/images/avi.jpg)