我已经从 Asset Store 下载了 FPS Constructor,但是,它是为较旧的 Unity API 制作的。我试图修复它,我大部分都理解它,但是我遇到了一个 C# 脚本(我对 C# 不熟悉)并且不知道如何修复它! 这是完整的脚本:
using UnityEngine;
using System.Collections;
public class LightningBolt : MonoBehaviour
{
public Transform target;
public int zigs = 100;
public float speed = 1f;
public float scale = 1f;
public Light endLight;
[HideInInspector] public bool emits = false;
Perlin noise;
float oneOverZigs;
private Particle[] particles;
void Start()
{
oneOverZigs = 1f / (float)zigs;
particleEmitter.emit = false;
particleEmitter.Emit(zigs);
particles = particleEmitter.particles;
}
void Update ()
{
if(target == null)
return;
if(!emits){
return;
}
endLight.intensity = 1;
if (noise == null)
noise = new Perlin();
float timex = Time.time * speed * 0.1365143f;
float timey = Time.time * speed * 1.21688f;
float timez = Time.time * speed * 2.5564f;
for (int i=0; i < particles.Length; i++)
{
Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i);
Vector3 offset = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
noise.Noise(timey + position.x, timey + position.y, timey + position.z),
noise.Noise(timez + position.x, timez + position.y, timez + position.z));
position += (offset * scale * ((float)i * oneOverZigs));
particles[i].position = position;
particles[i].color = Color.white;
particles[i].energy = 1f;
}
particleEmitter.particles = particles;
if (particleEmitter.particleCount >= 2)
{
if (endLight)
endLight.transform.position = particles[particles.Length - 1].position;
}
}
void EmitCharge (bool s) {
emits = s;
endLight.intensity = 0;
}
/* C
*/
void Target (Transform t) {
target = t;
}
}
如果您看得不完整 - 复制粘贴说明:
-
Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/PlasmaBeam/LightningBolt.cs(24,19): error CS1061: Type
UnityEngine.Component
does not contain a definition foremit
and no extension methodemit
of typeUnityEngine.Component
could be found. Are you missing an assembly reference? -
Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/PlasmaBeam/LightningBolt.cs(26,19): error CS1061: Type
UnityEngine.Component
does not contain a definition forEmit
and no extension methodEmit
of typeUnityEngine.Component
could be found. Are you missing an assembly reference? -
Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/PlasmaBeam/LightningBolt.cs(27,31): error CS1061: Type
UnityEngine.Component
does not contain a definition forparticles
and no extension methodparticles
of typeUnityEngine.Component
could be found. Are you missing an assembly reference? -
Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/Plasma Beam/LightningBolt.cs(58,19): error CS1061: Type
UnityEngine.Component
does not contain a definition forparticles
and no extension methodparticles
of typeUnityEngine.Component
could be found. Are you missing an assembly reference? -
Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/Plasma Beam/LightningBolt.cs(60,23): error CS1061: Type
UnityEngine.Component
does not contain a definition forparticleCount
and no extension methodparticleCount
of typeUnityEngine.Component
could be found. Are you missing an assembly reference?
最佳答案
Component.particleEmitter 在 5.6 中被移除。您应该使用 GetComponent 来获取 ParticleEmitter 组件。添加这些行,它应该会更好地工作:
ParticleEmitter particleEmitter;
void Start()
{
particleEmitter = GetComponent<ParticleEmitter>();
让我知道是否还有其他问题!如果您运行了 Unity 脚本升级程序,那么很有可能!
关于c# - 来自 Asset Store 的 FPS Constructor 中的 LightningBolt 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43250948/