-3
請幫我修復錯誤。 消息是: 「Assets/Scripts/GameManager.cs(6,21):error CS0118:GameManager.character' is a
field'but a type'expected。」 錯誤在(6,21)。謝謝。Unity腳本錯誤(錯誤CS0118)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour {
public List<character> character = new List<character>(); <-- (ERROR CS0118)
bool ShowCharWheel;
public int SelectedCharacter;
public int xcount;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
if(Input.GetKeyDown(KeyCode.C)){
{
ShowCharWheel = true;
}
{
ShowCharWheel = false;
}
//Camera.main.GetComponent<SmoothFollow>().target = characters[SelectedCharacter].
if (ShowCharWheel)
{
GUILayout.BeginArea(new Rect(Screen.width - 64, Screen.height - 192,64,192));
{
if(GUILayout.Button(c.icon,GUILayout.Width(64),GUILayout.Height(64)))
foreach (character c in Characters)
{
SelectedCharacter = character.IndexOf(c);
}
}
}
GUILayout.EndArea();
}
}
}
[System.Serializable]
public class Character
{
public string name;
public Texture2D icon;
public GameObject prefab;
public GameObject instance;
public Transform HomeSpawn;
}
除了代碼之外,還需要更多的細節,所以請忽略它。
我試過了,它給了我另一個錯誤。你能解決這個問題嗎? 「Assets/Scripts/GameManager.cs(34,50):error CS0246:無法找到類型或命名空間名稱'character'。您是否缺少using指令或程序集引用? –
@LightSpeedCo。你可能會遇到這種情況:'foreach(字符中的字符c)'。同樣的問題。你需要在'character'中大寫c,以便讀取'foreach(characterList中的字符c)'。我還將變量名稱更改爲我的。 – tnw