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.