[英]Instantiated ParticleSystem as GameObject not working in Unity c#
每当实例化 object 时,它会按照代码出现在场景中,但在游戏场景中什么也没有发生。 我尝试了所有方法。 我的程序有问题吗? 这阻止了我做我必须做的事情,并回到我的工作:
这是我的程序:
using UnityEngine;
public class Gun1 : MonoBehaviour
{
public float Damage = 10f;
public float range = 100f;
public float ImpactForce = 70f;
public float firerate = 15f;
public Camera fpscam;
public Camera scope;
public ParticleSystem muzzleflash;
public GameObject ImpactEffect;
private float nexttimetofire = 0f;
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Fire1") && Time.time >= nexttimetofire)
{
nexttimetofire = Time.time + 1f/firerate;
shoot();
}
void shoot()
{
muzzleflash.Play();
RaycastHit hit;
if(Physics.Raycast(fpscam.transform.position, fpscam.transform.forward, out hit, range))
{
Target target=hit.transform.GetComponent<Target>();
if(target != null)
{
target.TakeDamage(Damage);
}
if(hit.rigidbody != null)
{
hit.rigidbody.AddForce(-hit.normal * ImpactForce);
}
GameObject ImpactGO = Instantiate (ImpactEffect, hit.point, Quaternion.LookRotation (hit.normal));
Destroy(ImpactGO, 2f);
}
}
}
}
您是否在场景中添加粒子系统? 如果没有,添加它并将 object 与脚本链接。 否则,只需检查粒子系统是否链接到脚本。
如果 object 已链接,您可以检查 Unity 的这一部分:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.