10 Разброс при стрельбе, звуки выстрелов/попаданий


Hands:

using UnityEngine;
using System.Collections;

public class Hands2 : MonoBehaviour {
	/*
	 * 0-idle
	 * 1-takeSVU
	 * 2-takeSVU2
	 * 3-svuidle
	 * */
	public Transform SVU;
	public int mode;
	public int svumode;
	private float svutake1;
	private float svutake2;
	private float svustartrun;
	private float svuendrun;
	private float svureload;
	private float svuAim;
	private float svuRemove1;
	private float svuRemove2;
	public RaycastShooting2 rs;
	void Start()
	{
		animation["svutake1"].speed =2;
		animation["svutake2"].speed =2.5f;
		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)
		{
			rs.AimOff();
			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.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;
		}
		
		
		
		//SVU
		if(mode==3)
		{
			svutake2 = 0;
			if(svumode==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;
			}
		}

	}
}

RaycastShooting:

using UnityEngine;
using System.Collections;

public class RaycastShooting2 : MonoBehaviour {
	public Transform camera1;
	public Transform metalHit;
	public Transform MetalSparks;
	public Transform MuzzleFlash;
	public Transform hands;
	public Light MuzzleLight;
	public int BulletHoleLifeTime=15;
	private RaycastHit Hit;
	public float RateOfSpeed = 0.5f;
	private float _rateofSpeed;
	public Hands2 hd;
	private float muzzlelighttimeout=0.2f;
	public int curAmmo = 2;
	public int maxAmmo = 12;
	public int inventoryAmmo = 24;
	public float Accuracy = 0.01f;
	public Texture2D CrossFire;
	public Texture2D CrossFireBlack;
	public bool aim;
	public AudioClip shootSound;
	// Use this for initialization
	void Start () 
	{
		hands.animation["svushoot"].speed = 0.5f;
	}
	
	void Update () 
	{
		//Shooting
		if(_rateofSpeed<=RateOfSpeed)
		{
		_rateofSpeed += Time.deltaTime;
		}
		if(muzzlelighttimeout<0.1f)
		{
			muzzlelighttimeout+=Time.deltaTime;
			MuzzleLight.range = 10;
		}
		else
		{
			MuzzleLight.range = 0;
		}
		if(Input.GetMouseButtonDown(0)&_rateofSpeed>RateOfSpeed&hd.svumode==0&curAmmo>0)
		{
			audio.PlayOneShot(shootSound);
			curAmmo -= 1;
			muzzlelighttimeout=0;
			_rateofSpeed = 0;
			hands.animation.Play("svushoot", PlayMode.StopAll);
			Vector3 Direction = camera1.TransformDirection(Vector3.forward+new Vector3(Random.Range(-Accuracy,Accuracy),Random.Range(-Accuracy,Accuracy),0));
			MuzzleFlash.particleEmitter.emit = true;
			if(Physics.Raycast(camera1.position, Direction, out Hit, 10000f))
			{
				Quaternion HitRotation = Quaternion.FromToRotation(Vector3.up, Hit.normal);
				if(Hit.transform.rigidbody)
				{
					Hit.transform.rigidbody.AddForceAtPosition(Direction*1000, Hit.point);
				}
				if(Hit.collider.material.staticFriction==0.2f)
				{
					//Bullet Hole
					Transform metalhitGO = Instantiate(metalHit,Hit.point+(Hit.normal*0.005f),HitRotation) as Transform;
					metalhitGO.transform.parent = Hit.transform;
					Destroy((metalhitGO as Transform).gameObject, BulletHoleLifeTime);
					//Sparks
					Instantiate(MetalSparks,Hit.point+(Hit.normal*0.01f),HitRotation);
				}
			}
		}
		else
		{
			MuzzleFlash.particleEmitter.emit = false;
		}
		if(Input.GetKeyDown(KeyCode.R)&inventoryAmmo>0&curAmmo!=maxAmmo)
		{
			hd.svumode = 4;
		}
		if(Input.GetMouseButtonDown(1)&aim==false)
		{
			hd.svumode = 5;
		}
		if(Input.GetMouseButtonDown(1)&aim==true)
		{
			AimOff();
		}
	}
	public void Reload()
	{
		if(inventoryAmmo<maxAmmo - curAmmo)
		{
			curAmmo += inventoryAmmo;
			inventoryAmmo = 0;
		}
		else
		{
			inventoryAmmo -= maxAmmo - curAmmo;
			curAmmo += maxAmmo - curAmmo;
		}
	}
	public void Aim()
	{
		aim=true;
		camera1.camera.fieldOfView = 10;
		camera1.camera.depth = 2;
		GameSettings.Sens = 1;
		Messenger.Broadcast("aimMessage");
	}
	public void AimOff()
	{
		aim = false;
		camera1.camera.fieldOfView = 60;
		camera1.camera.depth = 0;
		GameSettings.Sens = 10;
		Messenger.Broadcast("aimMessage");
	}
	void OnGUI()
	{
		if(aim==true)
		{
		GUI.DrawTexture(new Rect(Screen.width/2-Screen.height/2,0,Screen.height,Screen.height), CrossFire);
		GUI.DrawTexture(new Rect(0,0,Screen.width/2-Screen.height/2, Screen.height), CrossFireBlack);
		GUI.DrawTexture(new Rect(Screen.width/2+Screen.height/2,0,Screen.width, Screen.height), CrossFireBlack);
		}
	}
}

Комментарии к этому посту

  • Ваня
    21.06.2014 at 19:25

    О да! Я так ждал! Спасибо!


  • Tyga
    18.07.2014 at 16:36

    Cool



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