- Home /
Question by
SulaimanWar · Sep 01, 2013 at 09:03 AM ·
gameobjectarraysaddcustomization
Filling up an array with GameObjects
I'm working on a weapon customisation script. In my weapon manager script I have:
var firstguns : GameObject[];
Which defines the weapon I begin with. So how do I make it like if Gun1 is active then add it to the firstguns variable Currently I have two other scripts related to this
Customisation Script(Attached to camera for the customisation): #pragma strict
private var wm : WeaponManager;
var no : int = 0;
function Start () {
}
function OnGUI () {
if (GUI.Button(new Rect(Screen.width / 2 - 0, Screen.height / 2 - 200, 200, 50), "Next Weapon"))
{
no++;
}
if (GUI.Button(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 200, 200, 50), "Previous Weapon"))
{
no--;
}
}
And then listNo(Attached to gun itself): #pragma strict
var index : int = 0;
var model : GameObject;
private var cusGO : GameObject;
private var cus : Customisation;
function Start () {
cusGO = GameObject.Find("Main Camera");
cus = cusGO.GetComponent(Customisation);
}
function Update () {
//Visibility
if(cus.no == index){
model.active = true;
}
if(cus.no != index){
model.active = false;
}
//====================================================
}
Comment