Question by
andreyazbyn · Sep 14, 2015 at 09:53 AM ·
c#scenesweapon systemweaponchanging
Weapon Select Menu
i want to make a weapon select screen in another scene (not in the main one beacause i dont want the players to change all weapons in game) here is the script for the weapon select screen(very simplified ) using UnityEngine; using System.Collections;
public class WeaponSelectScreen : MonoBehaviour {
public string MainMenu;
public GameObject playerGunsCanvas; //a empty game object as a child of a main canvas where you see the weapons that you chose
public GameObject weaponTypeSelectCanvas; //a empty game object as a child of a main canvas where you select the weapon type (primary, secondary)
public GameObject primaryWeaponsCanvas; //a empty game object as a child of a main canvas where you select the primary weapon type (assault rifle, smg, lmg...)
public GameObject assaultRiflesCanvas; //a empty game object as a child of a main canvas where you select the assault rifle (assault rifle 1 ,assault rifle 2...)
public GameObject assaultRiffle1Canvas; //a empty game object as a child of a main canvas where you select the assault rifle1 atatchments (atatchment 1 ,atatchment 2...)
public GameObject assaultRiffle2Canvas; //a empty game object as a child of a main canvas where you select the assault rifle atatchments (atatchments 1 ,atatchment 2...)
public GameObject assaultRiffle1Prefab;
public GameObject assaultRiffle2Prefab;
public GameObject atatchment1Prefab;
public GameObject atatchment2Prefab;
public GameObject atatchment3Prefab;
public void PrimaryWeaponMenu(){ //when the Primary Weapon button is pressed in the weaponTypeSelectCanvas
primaryWeaponsCanvas.SetActive(true);
assaultRiflesCanvas.SetActive(false);
assaultRiffle1Canvas.SetActive(false);
assaultRiffle1Canvas.SetActive(false);
weaponTypeSelectCanvas.SetActive(false);
playerGunsCanvas.SetActive(false);
}
public void AssaultRifleMenu(){ //when the AssaultRifle button is pressed in the primaryWeaponsCanvas
primaryWeaponsCanvas.SetActive(false);
assaultRiflesCanvas.SetActive(true);
assaultRiffle1Canvas.SetActive(false);
assaultRiffle1Canvas.SetActive(false);
weaponTypeSelectCanvas.SetActive(false);
playerGunsCanvas.SetActive(false);
}
public void AssaultRifle1Menu(){//when the AssaultRifle1 button is pressed in the assaultRiflesCanvas
primaryWeaponsCanvas.SetActive(false);
assaultRiflesCanvas.SetActive(false);
assaultRiffle1Canvas.SetActive(true);
assaultRiffle1Canvas.SetActive(false);
weaponTypeSelectCanvas.SetActive(false);
playerGunsCanvas.SetActive(false);
}
public void AssaultRifle2Menu(){//when the AssaultRifle2 button is pressed in the assaultRifflesCanvas
primaryWeaponsCanvas.SetActive(false);
assaultRiflesCanvas.SetActive(false);
assaultRiffle1Canvas.SetActive(false);
assaultRiffle1Canvas.SetActive(true);
weaponTypeSelectCanvas.SetActive(false);
}
public void ChangeLoadout(){//when the Change Loadout button is pressed in the playerGunsCanvas
primaryWeaponsCanvas.SetActive(false);
assaultRiflesCanvas.SetActive(false);
assaultRiffle1Canvas.SetActive(false);
assaultRiffle1Canvas.SetActive(false);
weaponTypeSelectCanvas.SetActive(true);
playerGunsCanvas.SetActive(false);
}
public void SaveMenu(){//when the Accept button is pressed in the assaultRiffle1Canvas or assaultRiffle1Canvas
primaryWeaponsCanvas.SetActive(false);
assaultRiflesCanvas.SetActive(false);
assaultRiffle1Canvas.SetActive(false);
assaultRiffle1Canvas.SetActive(false);
weaponTypeSelectCanvas.SetActive(false);
playerGunsCanvas.SetActive(true);
}
public void BackToMainMenu(){//when the Cancel button is pressed in any menu
Application.LoadLevel(MainMenu);
}
}
and this is the weapon switch script using UnityEngine; using System.Collections;
public class NewWeaponSwitch : MonoBehaviour {
public GameObject gun1;
public GameObject gun2;
public GameObject gun3;
public GameObject gun4;
// Use this for initialization
public void Start () {
// gun1 = GameObject.FindGameObjectWithTag("")
// gun1 = GameObject.FindGameObjectWithTag("")
}
// Update is called once per frame
public void Update () {
if (Input.GetButtonDown("SwitchWeapons")){
switchWeapons();
}
}
public void switchWeapons(){
if(gun1.activeSelf == true){
gun2.gameObject.SetActive(true);
gun1.gameObject.SetActive(false);
//Debug.Log("weapon1 active");
}
else if(gun2.activeSelf == true){
gun3.gameObject.SetActive(true);
gun2.gameObject.SetActive(false);
// Debug.Log("weapon2 active");
}
else if(gun3.activeSelf == true){
gun4.gameObject.SetActive(true);
gun3.gameObject.SetActive(false);
// Debug.Log("weapon2 active");
}
else if(gun4.activeSelf == true){
gun1.gameObject.SetActive(true);
gun4.gameObject.SetActive(false);
// Debug.Log("weapon2 active");
}
}
}
how can i make it so when you press the accept button the weapon gets set as gun1 in the level?
Comment