Files
FPS-Kit-2.0/Assets/FPS Kit Version 2.0/_CustomAssets/3D Models/WeaponPack II/Scripts/Switcher.cs
T
reedgamingstudio 5b8ebb7a35 test
testing
2014-12-16 00:23:12 -06:00

75 lines
2.2 KiB
C#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Switcher : MonoBehaviour {
public GUISkin guiStyle;
public List<GameObject> weapons;
int weapIndex = 0;
Controller ct;
// Use this for initialization
void Start () {
//Deactivate all weapons before start
for(int i = 0; i < weapons.Count; i ++){
weapons[i].SetActiveRecursively(false);
}
weapons[weapIndex].SetActiveRecursively(true);
weapons[weapIndex].SendMessage("TakeIn");
}
// Update is called once per frame
void Update () {
ct = weapons[weapIndex].GetComponent<Controller>();
//Previous weapon
if(Input.GetKeyDown(KeyCode.Alpha1)){
StartCoroutine(prevWeap(ct.switchTime));
}
//Next weapon
if(Input.GetKeyDown(KeyCode.Alpha2)){
StartCoroutine(nextWeap(ct.switchTime));
}
}
public IEnumerator prevWeap(float timer){
weapons[weapIndex].SendMessage("TakeOut");
yield return new WaitForSeconds(timer);
if(weapIndex > 0){
weapons[weapIndex].SetActiveRecursively(false);
weapIndex--;
weapons[weapIndex].SetActiveRecursively(true);
}else{
weapons[weapIndex].SetActiveRecursively(false);
weapIndex = weapons.Count-1;
weapons[weapIndex].SetActiveRecursively(true);
}
weapons[weapIndex].SendMessage("TakeIn");
}
public IEnumerator nextWeap(float timer){
weapons[weapIndex].SendMessage("TakeOut");
yield return new WaitForSeconds(timer);
if(weapIndex < weapons.Count-1){
weapons[weapIndex].SetActiveRecursively(false);
weapIndex++;
weapons[weapIndex].SetActiveRecursively(true);
}else{
weapons[weapIndex].SetActiveRecursively(false);
weapIndex = 0;
weapons[weapIndex].SetActiveRecursively(true);
}
weapons[weapIndex].SendMessage("TakeIn");
}
void OnGUI(){
GUI.skin = guiStyle;
GUI.Label(new Rect(5, 5, 500, 20), "[ " + (weapIndex+1).ToString() + " / " + weapons.Count + " ]" + " : " + weapons[weapIndex].name);
GUI.Label(new Rect(Screen.width-205, 5, 500, 20), "1 - Previous Weapon");
GUI.Label(new Rect(Screen.width-205, 25, 500, 20), "2 - Next Weapon");
GUI.Label(new Rect(Screen.width-205, 45, 500, 20), "LMB - Play Fire Animation");
GUI.Label(new Rect(Screen.width-205, 65, 500, 20), "R - Play Reload Animation");
}
}