test
testing
This commit is contained in:
+95
@@ -0,0 +1,95 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Controller : MonoBehaviour {
|
||||
|
||||
public enum Type {M79, M67, RPG, Bomb}
|
||||
public Type type;
|
||||
public Transform missile;
|
||||
public Transform FirePoint;
|
||||
public float switchTime;
|
||||
public float animSpeed = 1;
|
||||
public float fireRate = 0.1f;
|
||||
float nextFire = 0;
|
||||
|
||||
// Use this for initialization
|
||||
void Awake () {
|
||||
if(type != Type.M67 && type != Type.Bomb){
|
||||
animation["Fire"].wrapMode = WrapMode.Once;
|
||||
animation["Reload"].wrapMode = WrapMode.Once;
|
||||
animation["Idle"].wrapMode = WrapMode.Once;
|
||||
}else{
|
||||
if(type == Type.M67){
|
||||
animation["Throw"].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.M67 && type != Type.Bomb){
|
||||
RifleReload();
|
||||
}else{
|
||||
if(type == Type.M67 ){
|
||||
animation.Play ("Idle");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Input.GetMouseButtonDown(0)&&Time.time > nextFire && type != Type.Bomb){
|
||||
nextFire = Time.time + fireRate;
|
||||
if(type != Type.M67 && type != Type.Bomb){
|
||||
animation.Rewind("Fire");
|
||||
animation.CrossFade("Fire");
|
||||
animation["Fire"].speed = animSpeed;
|
||||
if(type == Type.RPG){
|
||||
Instantiate(missile, FirePoint.position, Quaternion.identity);
|
||||
}
|
||||
if(type == Type.M79){
|
||||
Rigidbody temp;
|
||||
temp = Instantiate(missile.rigidbody, FirePoint.position, Quaternion.identity) as Rigidbody;
|
||||
temp.velocity = FirePoint.TransformDirection(Vector3.forward*60);
|
||||
}
|
||||
}else{
|
||||
animation.Rewind("Throw");
|
||||
animation.CrossFade("Throw");
|
||||
animation["Throw"].speed = animSpeed;
|
||||
StartCoroutine(delayThrow(animSpeed/2));
|
||||
}
|
||||
}
|
||||
if( type == Type.Bomb){
|
||||
if(Input.GetMouseButton(0)){
|
||||
animation.CrossFadeQueued("Coding");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator delayThrow(float timer){
|
||||
yield return new WaitForSeconds(timer);
|
||||
Rigidbody temp;
|
||||
temp = Instantiate(missile.rigidbody, FirePoint.position, Quaternion.identity) as Rigidbody;
|
||||
temp.velocity = FirePoint.TransformDirection(Vector3.forward*60);
|
||||
}
|
||||
|
||||
void RifleReload(){
|
||||
AnimationState newReload = animation.CrossFadeQueued("Reload");
|
||||
newReload.speed = animSpeed;
|
||||
}
|
||||
|
||||
void TakeIn(){
|
||||
animation.Play("TakeIn");
|
||||
animation["TakeIn"].speed = animSpeed;
|
||||
}
|
||||
|
||||
void TakeOut(){
|
||||
animation.CrossFade("TakeOut");
|
||||
animation["TakeOut"].speed = animSpeed;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a93e36214e6cce043b31e9a9e8df0781
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Rocket : MonoBehaviour {
|
||||
|
||||
public float timeOut = 4.0f;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
Destroy (gameObject, timeOut);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
transform.Translate(new Vector3(0,0,1) * Time.deltaTime*150);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9697b60d936b24644889d1539346fde5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,74 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 734696929c0dfa0428ac29078f56701e
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Reference in New Issue
Block a user