- Home /
Question by
kimardamina · Jun 19, 2015 at 06:23 PM ·
programmingvariablesaccessing from any script
Accessing variables from other scripts
HI guy, i know this has been asked before already but after getting it write and checking what would have been the problem on my side I still dont get it.
So I am trying to get a Int variable from another script and testing the random generation of code in other script.
Here are the two scripts I am using, but then I am not getting any response showing that it is working in the console.
Anyone sees something which my eyes aint seeing that i am doing wrong? Appreciated
Script one: Random_Cards
static var card:int;
function Start () {
card = Random.Range(1, 5);
}
Second script which has to take the variable from the Random_Cards Script:
public var objScript:GameObject;
public var textShow:UI.Text;
function Start () {
var cardScript = objScript.GetComponent.<Random_Cards>();
Debug.Log("Collected Script");
textShow.text = " " + cardScript.card;
if(cardScript.card == 1){
Debug.Log("Number is 1");
}
if(cardScript.card == 2){
Debug.Log("Number is 2");
}
if(cardScript.card == 3){
Debug.Log("Number is 3");
}
if(cardScript.card == 4){
Debug.Log("Number is 4");
}
if(cardScript.card == 5){
Debug.Log("Number is 5");
}
}
Comment