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);
}
}
答案 0 :(得分:0)
在
行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);
}