[英]Got an error in unity3d with ima code
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.