使用 ima 代码在 unity3d 中出现错误
本文关键字:错误 unity3d ima 代码 使用 | 更新日期: 2023-09-27 18:37:09
Unity 错误说:
Assets/Scenes/Scripts/Items/CreateNewScroll.cs(23,33): error CS0117: `CreateNewScroll' does not contain a definition for `SpellEffectID'
文件名和类名似乎没问题。
using UnityEngine;
using System.Collections;
public class CreateNewScroll : MonoBehaviour {
private BaseScroll newScroll;
// Use this for initialization
void Start () {
CreateScroll();
Debug.Log (newScroll.ItemName);
Debug.Log (newScroll.ItemDescription);
Debug.Log (newScroll.ItemID.ToString());
Debug.Log (newScroll.spellEffectID.ToString());
}
private void CreateScroll(){
newScroll = new BaseScroll();
newScroll.ItemName = "Scroll";
newScroll.ItemDescription = "This is a powerfull scroll!";
newScroll.ItemID = Random.Range(1,101);
CreateNewScroll.SpellEffectID = Random.Range(500,1001);
}
}
在行中
CreateNewScroll.SpellEffectID = Random.Range(500,1001);
您指的是 CreateNewScroll
类上的静态字段,该字段在提供的代码中不存在。这是因为您直接引用类,而不是类的特定对象。
通过函数的其余部分,看起来应该在newScroll.spellEffectID
字段中
private void CreateScroll(){
newScroll = new BaseScroll();
newScroll.ItemName = "Scroll";
newScroll.ItemDescription = "This is a powerfull scroll!";
newScroll.ItemID = Random.Range(1,101);
newScroll.spellEffectID = Random.Range(500,1001);
}