Main Question
How do I make one script reference and compare the values of variables in another script on multiple game objects?
Info
I’m working on an RPG similar to Final Fantasy Tactics or Final Fantasy Tactics A2. I have the main cursor movement and maps done, but I still need to fix the unit system. The problem is I need a turn system that compares the speed values of all units, and makes the highest one go first, and I have no clue how to do this. If anyone could help me, it would be greatly appreciated.
What I Have:
Stats:
var maxHP = 10;
var maxMP = 10;
var str = 10;
var end = 10;
var prc = 10;
var wis = 10;
var res = 10;
var spd = 10;
var acc = 10;
var move = 5;
var jump = 2;
var curHP : int;
var curMP : int;
var redBox : GUIStyle;
var blueBox : GUIStyle;
var word : GUIStyle;
private var nextMove : float = 0.0;
function Start ()
{
curHP = maxHP;
curMP = maxMP;
}
function OnGUI ()
{
var hit : RaycastHit;
var layerMask = 1 << 9;
if (Physics.Raycast ((Vector3(0,-1,0) + transform.position), Vector3.one, hit, 1, layerMask))
{
GUI.Box (Rect (10,Screen.height-40,(Screen.width * curHP)/(2 * maxHP),20),"",redBox);
GUI.Box (Rect (10,Screen.height-70,(Screen.width * curMP)/(2 * maxMP),20),"",blueBox);
GUI.Box (Rect (10,Screen.height-40,(Screen.width/2),20), curHP+ "/" +maxHP, word);
GUI.Box (Rect (10,Screen.height-70,(Screen.width/2),20), curMP+ "/" +maxMP, word);
GUI.Box (Rect (10,Screen.height-85,(Screen.width/2),80), "");
}
if (curHP < 0)
curHP = 0;
if (curMP < 0)
curMP = 0;
if (curHP > 0)
curHP = maxHP;
if (curMP > 0)
curMP = maxMP;
}
Turn System(This is my problem):
//place >> turn start > units > turn end
// turn start - start of turn
// units - use units for movement, attack, and defence
// turn end - resets speed value and returns to start
function Start ()
{
BroadcastMessage("Place");
}
function Place ()
{
BroadcastMessage("Turn");
}
function Turn ()
{
var tem : Stats;
tem = gameObject.GetComponentInChildren(Stats);
}
function Update ()
{
}
I figured out how by myself…