一.闪光
将图片的shader改成particles->additive并作出相应闪光动画。
二.开枪动画
public class FirePistol : MonoBehaviour
{
public GameObject TheGun;
public GameObject MuzzleFlash;
public AudioSource GunFire;
public bool IsFiring = false;
public float TargetDistance;
public int DamageAmount=5;
void Update()
{
if (Input.GetButtonDown("Fire1") &&GlobalAmmo.ammoCount>=1)
{
if (IsFiring == false)
{
GlobalAmmo.ammoCount -= 1;
StartCoroutine(FiringPistol());
}
}
}
IEnumerator FiringPistol()
{
RaycastHit Shot;
IsFiring = true;
if(Physics.Raycast(transform.position,transform.TransformDirection(Vector3.forward),out Shot))
{
TargetDistance = Shot.distance;
Shot.transform.SendMessage("DamageZombie", DamageAmount, SendMessageOptions.DontRequireReceiver);
}
TheGun.GetComponent<Animation>().Play("PistolShot");
MuzzleFlash.SetActive(true);
MuzzleFlash.GetComponent<Animation>().Play("MuzzleAnim");
GunFire.Play();
yield return new WaitForSeconds(0.5f);
IsFiring = false;
}
}
这个代码包含了音效的使用时间并且包含了上一步使用的闪光动画。