我收到了一个错误,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);
}
}
}
发布于 2022-02-22 16:01:26
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://stackoverflow.com/questions/71224375
复制相似问题