我正在做一个FPS,下面是我的GunScript:
{
public float damage = 10f;
public float range = 100f;
public float fireRate = 5f;
public float impactForce = 30f;
public Camera playerCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;
private float nextTimeToFire = 0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / fireRate;
Shoot();
}
}
void Shoot()
{
muzzleFlash.Play();
RaycastHit hit;
if (Physics.Raycast(playerCam.transform.position, playerCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
if (hit.rigidbody != null)
{
hit.rigidbody.AddForce(-hit.normal * impactForce);
}
Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
}
}
}然而,粒子系统只在我按下鼠标或抬起鼠标时播放。当我的鼠标被按下时,它应该会连续播放。请提前帮助我,谢谢。
发布于 2020-08-13 23:56:55
我认为这里的问题是您只在Shoot()方法中播放它,该方法仅在每次发射时调用,但我不知道您的粒子系统是什么样子的。如果你想让它连续播放,你应该把它放在Update()中的一个单独的If语句中的Shoot()方法之外,或者像这样修改它:
if (Input.GetButton("Fire1"))
{
muzzleFlash.Play();
if (Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / fireRate;
Shoot();
}
}https://stackoverflow.com/questions/63383055
复制相似问题