NoGo86
1
Info… Ok I know this has been asked lots before but I have been through many answers and can still can not wrap my head around it. I have a Gameobject called MAP and a script attached to it called Start.
This is the Start script…
var SpawnPoint = Vector3(50,234.5,391.1545);
var Block : Transform;
var BlockAmount : int = 0;
function Update ()
{
//Spawning of the first block
if (BlockAmount == 0)
{
Instantiate (Block, SpawnPoint, Quaternion.identity);
BlockAmount ++;
}
}
Question… Why does this script on my player not change the BlockAmount Var in the Start script?
This is my PlayerScript
var BlockAmount1 : GameObject;
function Start()
{
BlockAmount1 = GameObject.Find("MAP");
}
function Update ()
{
//When its grounded
if(transform.position.y <= 25)
{
BlockAmount1.GetComponent(Start).BlockAmount = 0;
}
}
I have seen people change variables from different scripts using GetCompnent but I never do this. Use this example its pretty easy
firstScript.js
static var BlockAmount : int = 0;
secondScript.js
funciton Update(){
firstScript.BlockAmount = 10;
}
basically u call it a static var in the original script and then type scriptname.variablename then just use it normally and it will work.