4 Вспышка при стрельбе, искры при попадании

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 Hands2 hd;
	private float muzzlelighttimeout=0.2f;
	// Use this for initialization
	void Start () 
	{
		hands.animation["svushoot"].speed = 0.5f;
	}
	
	void Update () 
	{
		//Shooting
		if(muzzlelighttimeout<0.1f)
		{
			muzzlelighttimeout+=Time.deltaTime;
			MuzzleLight.range = 10;
		}
		else
		{
			MuzzleLight.range = 0;
		}
		if(Input.GetMouseButtonDown(0))
		{
			muzzlelighttimeout=0;
			hands.animation.Play("svushoot", PlayMode.StopAll);
			Vector3 Direction = camera1.TransformDirection(Vector3.forward);
			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.001f),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;
		}
	}
}

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