我收到一個錯誤,Assets\scripts\Skins.cs(9,12): error CS0116: A namespace cannot directly contain members such as fields or methods在互聯網上他們寫了錯誤放置括號的含義,但我沒有看到任何錯誤
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public GameObject choise1;
public GameObject choise2;
public GameObject choise3;
public int skin = 1;
public class Skins : MonoBehaviour {
void Choise () {
if (Input.GetMouseDown(choise1)){
choise2.SetActive (false);
}
}
}
uj5u.com熱心網友回復:
GameObject 和那個 int 皮膚需要在 Skins 類下,比如 Choise
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Skins : MonoBehaviour {
public GameObject choise1;
public GameObject choise2;
public GameObject choise3;
public int skin = 1;
void Choise () {
if (Input.GetMouseDown(choise1)){
choise2.SetActive (false);
}
}
}
如果你在這里仍然有一些問題,因為我不知道你想用那個 choiseX 做什么,也許你需要創建它們。我的意思是,也許你正在嘗試寫這樣的東西
void Choise () {
var GameObject choise1 = new GameObject();
var GameObject choise2 = new GameObject();
var GameObject choise3 = new GameObject();
int skin = 1;
if (Input.GetMouseDown(choise1)){
choise2.SetActive (false);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/432331.html
