资产商店的FPS构造函数中的LightningBolt脚本

时间:2017-04-06 09:22:25

标签: c# unity3d

我已从资源商店下载了FPS构造函数,但它是为较旧的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):错误CS1061:类型UnityEngine.Component不包含emit的定义且没有扩展名可以找到emit类型的方法UnityEngine.Component。你错过了装配参考吗?

  2.   

    资产/插件/ FPS构造函数V1 /演示资产/武器/ PlasmaBeam / LightningBolt.cs(26,19):错误CS1061:类型UnityEngine.Component不包含Emit的定义且没有扩展名可以找到Emit类型的方法UnityEngine.Component。你错过了装配参考吗?

  3.   

    Assets / Plugins / FPS Constructor V1 / Demo Assets / Weapons / PlasmaBeam / LightningBolt.cs(27,31):错误CS1061:类型UnityEngine.Component不包含particles的定义且没有扩展名可以找到particles类型的方法UnityEngine.Component。你错过了装配参考吗?

  4.   

    资产/插件/ FPS构造函数V1 /演示资产/武器/等离子束/ LightningBolt.cs(58,19):错误CS1061:类型UnityEngine.Component不包含particles的定义,不可以找到类型为particles的扩展方法UnityEngine.Component。你错过了装配参考吗?

  5.   

    资产/插件/ FPS构造函数V1 /演示资产/武器/等离子束/ LightningBolt.cs(60,23):错误CS1061:类型UnityEngine.Component不包含particleCount的定义,不可以找到类型为particleCount的扩展方法UnityEngine.Component。你错过了装配参考吗?

1 个答案:

答案 0 :(得分:0)

在5.6中删除了Component.particleEmitter。您应该使用GetComponent来获取ParticleEmitter组件。添加这些行,它应该更好:

ParticleEmitter particleEmitter;

void Start()
{
    particleEmitter = GetComponent<ParticleEmitter>();   

如果其他任何内容无效,请告诉我!如果您运行Unity脚本升级的东西,可能会有!