13 простреливаемость

Скрипт:

{
	public Transform attackPoint;
	public Transform MetalHit;
	public Transform Sparks;
	public float AttackSpeed;
	private float timeout;
	private float scatterx;
	private float scattery;
	private float scatterz;
	public AnimationClip shoot;
	public AudioClip aushoot;
	void Start () 
	{

	}
	void Update () 
	{
		if(timeout<AttackSpeed)
		{
			timeout += Time.deltaTime;
		}
		if(Input.GetMouseButton(0))
		{
			animation.clip = shoot;
			animation.Play();
			audio.pitch = Random.Range(0.8f,1);
			audio.PlayOneShot(aushoot);
			scatterx = Random.Range(-0.1f,0.1f);
			scattery = Random.Range(-0.1f,0.1f);
			scatterz = Random.Range(-0.1f,0.1f);
			timeout = 0;
			Ray ray1 = new Ray(attackPoint.position,attackPoint.forward+new Vector3(scatterx,scattery,scatterz));
			RaycastHit hit1;
			RaycastHit hit2;
			RaycastHit hit3;
			if(Physics.Raycast(ray1,out hit1,100))
			{
				Quaternion hit1Rotation = Quaternion.FromToRotation(Vector3.up,hit1.normal);
				Instantiate(Sparks,hit1.point+(hit1.normal*0.01f),hit1Rotation);
				Transform metalHit = Instantiate(MetalHit,hit1.point+(hit1.normal*0.01f),hit1Rotation) as Transform;
				metalHit.parent = hit1.transform;
				Ray ray2 = new Ray(hit1.point+ray1.direction*1.2f,-attackPoint.forward+new Vector3(scatterx,scattery,scatterz));
				if(Physics.Raycast(ray2,out hit2,3))
				{
					Quaternion hit2Rotation = Quaternion.FromToRotation(Vector3.up,hit2.normal);
					Instantiate(Sparks,hit2.point+(hit2.normal*0.01f),hit2Rotation);
					Transform metalHit2 = Instantiate(MetalHit,hit2.point+(hit2.normal*0.01f),hit2Rotation) as Transform;
					metalHit2.parent = hit2.transform;
					Ray ray3 = new Ray(hit2.point,attackPoint.forward+new Vector3(scatterx,scattery,scatterz));
					if(Physics.Raycast(ray3,out hit3,75))
					{
						Quaternion hit3Rotation = Quaternion.FromToRotation(Vector3.up,hit3.normal);
						Instantiate(Sparks,hit3.point+(hit3.normal*0.01f),hit3Rotation);
						Transform metalHit3 = Instantiate(MetalHit,hit3.point+(hit3.normal*0.01f),hit3Rotation) as Transform;
						metalHit3.parent = hit3.transform;
					}
				}
			}
		}
	}
}

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

  • Persik
    28.01.2015 at 21:20

    Ооооо, спасибо тебе:) Продолжай дальше в том же духе:)



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