12 настройка гранатомёта



Для ракеты (Rocket2):

using UnityEngine;
using System.Collections;

public class Rocket2 : MonoBehaviour 
{
	public bool Activate;
	public float Speed;
	private float timeout;
	private float lifetimeout;
	private int _scatter;
	public int Scatter;
	public Transform physicExplosion;
	public Transform graphicExplosion;
	public Transform Smoke;
	public Transform Fire;
	// Use this for initialization
	void Start () {
		Smoke.GetComponent<ParticleEmitter>().emit = false;
		Fire.GetComponent<ParticleEmitter>().emit = false;
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(Activate==true)
		{
			if(Smoke.GetComponent<ParticleEmitter>().emit==false)
			{
				Smoke.GetComponent<ParticleEmitter>().emit = true;
			}
			if(Fire.GetComponent<ParticleEmitter>().emit==false)
			{
				Fire.GetComponent<ParticleEmitter>().emit = true;
			}
			timeout+=Time.deltaTime;
			lifetimeout+=Time.deltaTime;
			if(timeout>2)
			{
				_scatter = Random.Range(-Scatter,Scatter);
				timeout = 0;
			}
			transform.Translate(Vector3.forward*Speed*Time.deltaTime);
			transform.RotateAround(transform.position, transform.TransformDirection(Vector3.right), _scatter*Time.deltaTime);
			transform.RotateAround(transform.position, transform.TransformDirection(Vector3.up), _scatter*Time.deltaTime);
			if(Physics.Raycast(transform.position,transform.TransformDirection(Vector3.forward),1.4f))
			{
				Dead();
			}
			if(lifetimeout>10)
			{
				Dead();
			}
		}
	}
	void Dead()
	{
		Instantiate(physicExplosion,transform.position+transform.TransformDirection(Vector3.forward)*1.4f,transform.rotation);
		Instantiate(graphicExplosion,transform.position+transform.TransformDirection(Vector3.forward)*1.4f,transform.rotation);
		Smoke.GetComponent<ParticleEmitter>().emit = false;
		Smoke.parent = null;
		Destroy(Smoke.gameObject,7);
		Destroy(gameObject);
	}
	
	void OnDrawGizmos()
	{
		Gizmos.color = Color.red;
		Gizmos.DrawRay(transform.position,transform.TransformDirection(Vector3.forward)*1.4f);
	}
}

Для рук (Hands3):

using UnityEngine;
using System.Collections;

public class Hands3 : MonoBehaviour {
	public Transform SVU;
	public Transform RPG;
	public Transform RPGFakeGrenade;
	public Transform RocketRespawn;
	public Transform Rocket;
	public int mode;
	public int svumode;
	public int rpgmode;
	private float svutake1;
	private float svutake2;
	private float svustartrun;
	private float svuendrun;
	private float svureload;
	private float svuAim;
	private float svuRemove1;
	private float svuRemove2;
	private float rpgtake1;
	private float rpgtake2;
	private float rpgstartrun;
	private float rpgendrun;
	private float rpgstartaim;
	private float rpgendaim;
	private float rpgaimstartrun;
	private float rpgaimendrun;
	private float rpgreload1;
	private float rpgreload2;
	private float rpgreload3;
	public RaycastShooting2 rs;
	void Start()
	{
		animation["svutake1"].speed =2;
		animation["svutake2"].speed =2.5f;
		animation["SvuRemove1"].speed =2;
		animation["SvuRemove1"].speed =2;
		animation["svuendrun"].speed = 1.8f;
		animation["svurun"].speed = 2;
		animation["svuAim"].speed = 0.5f;
	}
	// Update is called once per frame
	void Update () 
	{
		//Hands
		if(mode==0)
		{
		animation.Play("idle", PlayMode.StopAll);
		}
		if(Input.GetKeyDown(KeyCode.Alpha2)&mode==3)
		{
			animation.Play("SvuRemove1", PlayMode.StopAll);
			mode = 4;
		}
		if(mode==4)
		{
			svuRemove1 += Time.deltaTime;
			
		}
		if(svuRemove1>animation["SvuRemove1"].length)
		{
			SVU.GetComponent<MeshRenderer>().enabled = false;
			SVU.GetComponent<RaycastShooting2>().enabled = false;
			animation.Play("SvuRemove2", PlayMode.StopAll);
			svuRemove1 = 0;
			mode = 5;
		}
		if(mode==5)
		{
			svuRemove2+=Time.deltaTime;
		}
		if(svuRemove2>=animation["SvuRemove2"].length)
		{
			mode = 0;
			svuRemove2 = 0;
		}
		if(Input.GetKeyDown(KeyCode.Alpha3)&mode==0)
		{
			animation.Play("rpgtake1", PlayMode.StopAll);
			mode=6;
		}
		if(mode==6)
		{
			rpgtake1+=Time.deltaTime;
		}
		if(rpgtake1>=animation["rpgtake1"].length)
		{
			rpgtake1 = 0;
			mode = 7;
			animation.Play("rpgtake2", PlayMode.StopAll);
			RPG.GetComponent<MeshRenderer>().enabled = true;
			RPG.GetComponent<RPG2>().enabled = true;
			if(RPG.GetComponent<RPG2>().CanShoot==true)
			{
				Transform go = Instantiate(Rocket,RocketRespawn.position,RocketRespawn.rotation) as Transform;
				go.parent = RPG;
			}
		}
		if(mode==7)
		{
			rpgtake2+=Time.deltaTime;
		}
		if(rpgtake2>=animation["rpgtake2"].length)
		{
			mode=8;
		}
		if(Input.GetKeyDown(KeyCode.Alpha2)&mode==0)
		{
			animation.Play("svutake1", PlayMode.StopAll);
			mode=1;
		}
		if(mode==1)
		{
			svutake1 += Time.deltaTime;
		}
		if(svutake1>=animation["svutake1"].length/2)
		{
			SVU.GetComponent<MeshRenderer>().enabled = true;
			SVU.GetComponent<RaycastShooting2>().enabled = true;
			animation.Play("svutake2", PlayMode.StopAll);
			svutake1 = 0;
			mode=2;
		}
		if(mode==2)
		{
			svutake2 += Time.deltaTime;	
		}
		if(svutake2>=animation["svutake2"].length/2.5f)
		{
			mode=3;
		}
		
		
		//RPG
		if(mode==8)
		{
			if(rpgmode<10)
			{
				if(rpgmode==0)
				{
					rpgtake2 = 0;
					animation.CrossFade("rpgidle");
					if(Input.GetButton("Vertical"))
					{
						animation.CrossFade("rpgstartrun");
						rpgmode=1;
					}
				}
				if(rpgmode==1)
				{
					rpgstartrun += Time.deltaTime;
				}
				if(rpgstartrun>=animation["rpgstartrun"].length)
				{
					animation.CrossFade("rpgrun");
					rpgstartrun = 0;
				}
				if(Input.GetButtonUp("Vertical"))
				{
					rpgmode = 3;
					animation.CrossFade("rpgendrun");
				}
				if(rpgmode==3)
				{
					rpgendrun += Time.deltaTime;
				}
				if(rpgendrun>=animation["rpgendrun"].length)
				{
					rpgendrun = 0;
					rpgmode = 0;
				}
				if(Input.GetMouseButtonDown(1)&rpgmode<4)
				{
					rpgmode = 10;
					animation.CrossFade("rpgstartaim");
				}
				if(Input.GetKeyDown(KeyCode.R)&RPG.GetComponent<RPG2>().CanShoot==false&rpgmode<4)
				{
					rpgmode = 4;
					animation.CrossFade("rpgreload1");
				}
				if(rpgmode==4)
				{
					rpgreload1 += Time.deltaTime;
				}
				if(rpgreload1>animation["rpgreload1"].length)
				{
					rpgreload1 = 0;
					RPGFakeGrenade.GetComponent<MeshRenderer>().enabled = true;
					animation.CrossFade("rpgreload2");
					rpgmode = 5;
				}
				if(rpgmode==5)
				{
					rpgreload2 += Time.deltaTime;
				}
				if(rpgreload2>animation["rpgreload2"].length)
				{
					rpgreload2 = 0;
					RPGFakeGrenade.GetComponent<MeshRenderer>().enabled = false;
					Transform go = Instantiate(Rocket,RocketRespawn.position,RocketRespawn.rotation) as Transform;
					go.parent = RPG;
					rpgmode = 6;
					animation.CrossFade("rpgreload3");
				}
				if(rpgmode==6)
				{
					rpgreload3 += Time.deltaTime;
				}
				if(rpgreload3>animation["rpgreload3"].length)
				{
					RPG.GetComponent<RPG2>().CanShoot = true;
					rpgreload3 = 0;
					rpgmode = 0;
				}
			}
			else
			{
				if(rpgmode==10)
				{
					rpgstartaim += Time.deltaTime;
				}
				if(rpgstartaim>=animation["rpgstartaim"].length)
				{
					rpgmode=11;
				}
				if(rpgmode==11)
				{
					rpgstartaim = 0;
					animation.CrossFade("rpgaimidle");
					if(Input.GetButton("Vertical"))
					{
						animation.CrossFade("rpgaimrunstart");
						rpgmode=13;
					}
				}
				if(Input.GetMouseButtonDown(1))
				{
					animation.CrossFade("rpgaimend");
					rpgmode = 12;
				}
				if(rpgmode==12)
				{
					rpgendaim += Time.deltaTime;
				}
				if(rpgendaim>=animation["rpgaimend"].length)
				{
					rpgendaim = 0;
					rpgmode = 0;
				}
				if(rpgmode==13)
				{
					rpgaimstartrun += Time.deltaTime;
				}
				if(rpgaimstartrun>=animation["rpgaimrunstart"].length)
				{
					rpgmode = 14;
				}
				if(rpgmode==14)
				{
					animation.CrossFade("rpgaimrun");
					rpgaimstartrun = 0;
				}
				if(Input.GetButtonUp("Vertical"))
				{
					rpgmode = 15;
					animation.CrossFade("rpgaimrunend");
				}
				if(rpgmode==15)
				{
					rpgaimendrun += Time.deltaTime;
				}
				if(rpgaimendrun>=animation["rpgaimrunend"].length)
				{
					rpgaimendrun = 0;
					rpgmode = 11;
				}
			}
		}
		//SVU
		if(mode==3)
		{
			if(svumode==0)
			{
				svutake2 = 0;
				animation.CrossFade("svuidle");
				if(Input.GetButton("Vertical"))
				{
					animation.CrossFade("svustartrun");
					svumode=1;
				}
			}
			if(svumode==1)
			{
				svustartrun += Time.deltaTime;
			}
			if(svustartrun>=animation["svustartrun"].length)
			{
				svumode = 2;
			}
			if(svumode==2)
			{
				//animation.Play("svurun", PlayMode.StopAll);
				animation.CrossFade("svurun");
				svustartrun = 0;
			}
			if(Input.GetButtonUp("Vertical")&svumode!=4)
			{
				svumode = 3;
				animation.CrossFade("svuendrun");
			}
			if(svumode==3)
			{
				svuendrun += Time.deltaTime;
			}
			if(svuendrun>=animation["svuendrun"].length/1.8f)
			{
				svumode=0;
				svuendrun = 0;
			}
			//Reload
			if(svumode==4)
			{
				animation.Play("svureload", PlayMode.StopAll);
				svureload+=Time.deltaTime;
				rs.AimOff();
			}
			if(svureload>=animation["svureload"].length)
			{
				rs.Reload();
				svumode = 0;
				svureload = 0;
			}
			//Aim
			if(svumode==5)
			{
				animation.Play("svuAim", PlayMode.StopAll);
				svuAim+=Time.deltaTime;
			}
			if(svuAim>=animation["svuAim"].length)
			{
				rs.Aim();
				svumode = 0;
				svuAim = 0;
			}
		}

	}
}

Для гранатомёта (RPG2):

using UnityEngine;
using System.Collections;

public class RPG2 : MonoBehaviour 
{
	public bool CanShoot;
	void Update () 
	{
		if(Input.GetMouseButtonDown(0)&CanShoot==true)
		{
			Transform Rocket = transform.Find("Rocket(Clone)");
			Rocket.GetComponent<Rocket2>().Activate = true;
			Rocket.parent = null;
			CanShoot = false;
		}
	}
}

Оставить комментарий