Spaceship game, Pick weapon

Hello! I am making a 2D spaceship shooter game, seen from above, kinda like the old meteor game. I am trying to make a menu where you can equip your ship with weapons of your own choice. I am having problems with trying to move the picked weapon (a projectile gameobject) from my menu script to my fire script. I am using arrays in my both scripts but I get errors here and there. Any help would be much appreciated! Here are the scripts:

private var playerShip : GameObject;

private var weaponTypes : int[];
public var plasma : GameObject;
public var bluePlasma : GameObject;


private var pekare : int = 0;


private var widthe : int = 200;
private var heighte : int = 80;
private var placeEquip : Rect = new Rect(widthe/4, heighte/2, widthe, heighte * 8);

private var spot1 : Rect;
private var spot2 : Rect;
private var spot3 : Rect;
private var spot4 : Rect;
private var spot5 : Rect;
private var spot6 : Rect;
private var spot7 : Rect;
private var spot8 : Rect;
private var spot9 : Rect;


private var placeUnequip : Rect = new Rect(widthe/4 + widthe + 5, heighte/2, widthe, heighte * 8);

private var plasmaEquipped : boolean = false;
private var bluePlasmaEquipped : boolean = false;
private var redPlasmaEquipped : boolean = false;
private var greenPlasmaEquipped : boolean = false;


function Start () {
	playerShip = GameObject.FindGameObjectWithTag("ThePlayer").gameObject;
	
	
		spot1 = new Rect(10, 20, 100, 20);
		spot2 = new Rect(10, 45, 100, 20);
		spot3 = new Rect(10, 70, 100, 20);
		spot4 = new Rect(10, 95, 100, 20);
		spot5 = new Rect(10, 115, 100, 20);
		spot6 = new Rect(10, 135, 100, 20);
		spot7 = new Rect(10, 150, 100, 20);
		spot8 = new Rect(10, 175, 100, 20);
		spot9 = new Rect(10, 120, 100, 20);

	
}


function OnGUI(){

	
	if(GUI.Button(Rect(Screen.width/2, Screen.height/2, 100, 100), "Send")){
		for(var i = 0; weaponTypes *!= null; i++){*

_ playerShip.transform.FindChild(“Weapons”).gameObject.GetComponent(FireScript).receiveValue(weaponTypes*, i, 0.4, 900);_
_
}_
_
}*_

placeEquip = GUI.Window (0, placeEquip, EquipFunction, “Weapons Avaible”);
* placeUnequip = GUI.Window(1, placeUnequip, UnEquipFunction, “Weapons Equipped”);*
}

function EquipFunction(windowID : int){
if(plasmaEquipped == false){
* if (GUI.Button (spot1, “Plasma”)){*
* weaponTypes[pekare] = 1;*
* pekare++;*
* plasmaEquipped = true;*

* }*
* }*
*if(bluePlasmaEquipped == false){ *
* if (GUI.Button (spot2, “Blue Plasma”)){*
* weaponTypes[pekare] = 2;*
* pekare++;*
* bluePlasmaEquipped = true;*
* }*
* }*
}

function UnEquipFunction(windowID : int){
if(plasmaEquipped == true){
* if (GUI.Button (spot1, “Plasma”)){*

* plasmaEquipped = false;*
* }*
* }*
*if(bluePlasmaEquipped == true){ *
* if (GUI.Button (spot2, “Blue Plasma”)){*
* bluePlasmaEquipped = false;*
* }*
* }*
}

Shoot script:
#pragma strict
public var slots : GameObject[];

private var weapon : GameObject[];
private var forceProj : float[];
private var reloadTime : float[];
private var timerRel : float[];

/**
public var plasmaProj : GameObject;

public var bluePlasmaProj : GameObject;
**/

public var plasma : GameObject;
public var bluePlasma : GameObject;

//private var slot1Wep : GameObject;

//public var slot1Reload : float = 1;
private var timer : float;
/**
public var force1 : float;
public var force2 : float;
public var force3 : float;
public var rel1 : float;
public var rel2 : float;
public var rel3 : float;
private var timerRel1 : float;
private var timerRel2 : float;
private var timerRel3 : float;
**/
function Start () {
//timerRel = slotsReloadTime;

timerRel[0] = 0;
}

function Update () {
* //shoot part*

* //slot1 weapon*

* if(Input.GetKey(KeyCode.Space)){*
* var arr = slots;*
* for(var i = 0; i < arr.Length; i++){*

_ if(timerRel < Time.time){
timerRel = 0;_

var copyPar = Instantiate(weapon_, slots*.transform.position, this.transform.rotation);*_

_ copyPar.rigidbody.velocity = this.transform.forward * forceProj*;*_

* Destroy(copyPar, 5);*
* timer = Time.time + 0.2;*
timerRel = Time.time + reloadTime*;*
* }*

* }*
* }*
}

function receiveValue(projectileType : int, spotPut : int, rel : float, force : float){

* if(projectileType == 1){*
* weapon[spotPut] = plasma;*
* }*
* else if(projectileType == 2){*
* weapon[spotPut] = bluePlasma;*
* }*
* reloadTime[spotPut] = rel;*

* forceProj[spotPut] = force;*

}

Sorry for unused variables and such which might make it harder to read.

I see what you’re trying to do, I think. You mentioned some problems and errors you were having. Comment to this with the types of errors you’re seeing, exactly.

Here’s what I gather… You have a GUI button and two windows displaying some options. I’m a little confused on the “Send” button because it looks like you call receiveValue for each of the weapon choices when it is pressed.

Nonetheless, my answer to your issue relates to the two “weapons” arrays. The weapons array in “Shoot” only serves the function of storage of a set of GameObjects, but a better alternative would be a data-structure that allows you to index that set of object instances easily. So, instead of weapons : GameObject, I’d use a Dictionary. For example

// declaration:
var myDictionary = new Dictionary.<KeyType,ValueType>();

// and a real-world declaration example (where 'Person' is a custom class):
var myContacts = new Dictionary.<string,Person>();

// insert or change the value for the given key
myDictionary[anyKey] = newValue;                 

// retrieve a value for the given key
var thisValue = myDictionary[theKey];      

// get the number of items in the Hashtable
var howBig = myDictionary.Count;                 

// remove the key & value pair from the Hashtable, for the given key.
myDictionary.Remove(theKey);

With this data-structure, you still have a set of GameObjects, but you can reference them according to their name. For example, in “Shoot” you would initialize the Dictionary like this.

function Start()
{
  myDictionary["Plasma"] = plasma;
  myDictionary["Blue Plasma"] = bluePlasma
}

So, now that you can access the weapon objects using a string, you should use these strings in your other script with OnGUI() to make selections. For example…

var weapons : List.<string>();

...

function Start()
{
   weapons.Add("Plasma");
   weapons.Add("Blue Plasma");
}

...

for(var weaponName:String in weapons){
  if(GUI.Button(Rect(Screen.width/2, Screen.height/2, 100, 100), weaponName)){
     playerShip.transform.FindChild("Weapons").gameObject.GetComponent(FireScript).receiveValue(weaponName, 0.4, 900);
  }
}

You’ve got to work out one other issue with which one of these two scripts will “contain” the weapons data. In other words, You don’t want weapon-name strings defined in one script that may or may not correspond to the keys of a dictionary of another script.

Get back to me if you need other help, but I think you probably just have to get some of this basic stuff figured out. Figure out how to use this language effectively. Learn about encapsulation a little because you’re probably going to want to have the weapon types defined in one place, and just pass the float value to the “Shoot” script on whatever weapon object is firing it.