c# - 来自 Asset Store 的 FPS Constructor 中的 LightningBolt 脚本

标签 c# unity3d

我已经从 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;
    }
}

这是错误截图。 enter image description here

如果您看得不完整 - 复制粘贴说明:

  1. Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/PlasmaBeam/LightningBolt.cs(24,19): error CS1061: Type UnityEngine.Component does not contain a definition for emit and no extension method emit of type UnityEngine.Component could be found. Are you missing an assembly reference?

  2. Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/PlasmaBeam/LightningBolt.cs(26,19): error CS1061: TypeUnityEngine.Component does not contain a definition for Emit and no extension method Emit of type UnityEngine.Component could be found. Are you missing an assembly reference?

  3. Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/PlasmaBeam/LightningBolt.cs(27,31): error CS1061: TypeUnityEngine.Component does not contain a definition for particles and no extension method particles of type UnityEngine.Component could be found. Are you missing an assembly reference?

  4. Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/Plasma Beam/LightningBolt.cs(58,19): error CS1061: Type UnityEngine.Component does not contain a definition for particles and no extension method particles of type UnityEngine.Component could be found. Are you missing an assembly reference?

  5. Assets/Plugins/FPS Constructor V1/Demo Assets/Weapons/Plasma Beam/LightningBolt.cs(60,23): error CS1061: Type UnityEngine.Component does not contain a definition for particleCount and no extension method particleCount of type UnityEngine.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/

相关文章:

c# - 在共享数据结构上同步

c# - 自定义 Asp.Net Identity 3.0

android - Gradle 对 Unity 的依赖

unity3d - 命名空间 'UnityEngine' 中不存在“UI”

android - Gradle(Android Studio)不会生成jar文件

c# - HttpListener : writing to outputstream slow depending on content?

c# - 制作我的 Windows 窗体/应用程序的较小屏幕分辨率版本的最简单方法?

c# - 当程序最后一次通过 WaitForSeconds 时,Unity 崩溃

c# - 在 Unity 中将 Vector3 转换为 float

c# - 如何将样式放在单独的 .xaml 文件中