14 рикошет



Скрипт:

using UnityEngine;
using System.Collections;

public class Shooterv3 : MonoBehaviour 
{
	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;
	private int RanShoot;
	void Start () 
	{
	
	}
	void Update () 
	{
		if(timeout<AttackSpeed)
		{
			timeout += Time.deltaTime;
		}
		if(Input.GetMouseButton(0)&&timeout>AttackSpeed)
		{
			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;
			RaycastHit hit10;
			if(Physics.Raycast(ray1,out hit1,100))
			{
				RanShoot = Random.Range(0,10);
				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;
				if(RanShoot==0)
				{
					Ray ray10 = new Ray(hit1.point,Vector3.Reflect(ray1.direction,hit1.normal));
					if(Physics.Raycast(ray10,out hit10,100))
					{
						Quaternion hit10Rotation = Quaternion.FromToRotation(Vector3.up,hit10.normal);
						Instantiate(Sparks,hit10.point+(hit10.normal*0.01f),hit10Rotation);
						Transform metalHit10 = Instantiate(MetalHit,hit10.point+(hit10.normal*0.01f),hit10Rotation) as Transform;
						metalHit10.parent = hit10.transform;
					}
				}
				else
				{
					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;
						}
					}
				}
			}
		}
	}
}

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