testing
This commit is contained in:
reedgamingstudio
2014-12-16 00:23:12 -06:00
parent c0c0755cc6
commit 5b8ebb7a35
1697 changed files with 1115979 additions and 0 deletions
@@ -0,0 +1,84 @@
using UnityEngine;
using System.Collections;
public class WeaponController : MonoBehaviour {
public enum Type {Sniper, Rifle, Automatic, Knife}
public Type type;
public float animSpeed = 1;
public float fireRate = 0.1f;
float nextFire = 0;
// Use this for initialization
void Awake () {
if(type == Type.Sniper){
animation["Reload_1_3"].wrapMode = WrapMode.Once;
animation["Reload_2_3"].wrapMode = WrapMode.Once;
animation["Reload_3_3"].wrapMode = WrapMode.Once;
}
if(type == Type.Rifle){
animation["Reload"].wrapMode = WrapMode.Once;
}
animation["Fire"].wrapMode = WrapMode.Once;
animation["Idle"].wrapMode = WrapMode.Once;
animation["TakeIn"].wrapMode = WrapMode.Once;
animation["TakeOut"].wrapMode = WrapMode.Once;
//animation.Play("Idle");
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.R)){
if(type == Type.Sniper){
SniperReload();
}
if(type == Type.Rifle || type == Type.Automatic){
RifleReload();
}
}
if(type != Type.Automatic){
if(Input.GetMouseButtonDown(0)&&Time.time > nextFire){
nextFire = Time.time + fireRate;
animation.Rewind("Fire");
AnimationState fire = animation.CrossFadeQueued("Fire");
fire.speed = animSpeed;
}
}else{
if(Input.GetMouseButton(0)&&Time.time > nextFire){
nextFire = Time.time + fireRate;
animation.Rewind("Fire");
animation.CrossFade("Fire");
animation["Fire"].speed = animSpeed;
}
}
}
void RifleReload(){
AnimationState newReload = animation.CrossFadeQueued("Reload");
newReload.speed = animSpeed;
}
void SniperReload(){
AnimationState newReload1 = animation.CrossFadeQueued("Reload_1_3");
newReload1.speed = animSpeed;
//4 is number of bullets to reload
for(int i = 0; i < 4; i++){
AnimationState newReload2 = animation.CrossFadeQueued("Reload_2_3");
newReload2.speed = animSpeed;
}
AnimationState newReload3 = animation.CrossFadeQueued("Reload_3_3");
newReload3.speed = animSpeed;
}
void TakeIn(){
animation.Play("TakeIn");
animation["TakeIn"].speed = animSpeed;
}
void TakeOut(){
animation.CrossFade("TakeOut");
animation["TakeOut"].speed = animSpeed;
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bdbd684ec89d84f44b18233c99c3e849
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,72 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class WeaponSwitcher : MonoBehaviour {
public GUISkin guiStyle;
public List<GameObject> weapons;
public float switchTime = 1;
int weapIndex = 0;
// 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 () {
//Previous weapon
if(Input.GetKeyDown(KeyCode.Alpha1)){
StartCoroutine(prevWeap(switchTime));
}
//Next weapon
if(Input.GetKeyDown(KeyCode.Alpha2)){
StartCoroutine(nextWeap(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");
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8896e6d255b64e54f9a3837d389f36a2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: