gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:06:29 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com