Unity入门,这个问题很是不懂
问题描述:
麻烦来个好心人解答一下这是怎么回事,我是按书上打的代码,怎么会错
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class hellowolrd. : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
void OnGUI()
{
GUI.skin.label.fontSize = 100;
GUI.Label(new Rect(10, 10, Screen.width, Screen.height), "Hello World");
}
}
}
答
首先楼上说的C#本身是支持函数嵌套的,这块从语法上讲没错误,错误应该在于hellowolrd. 后面的这个点,C#是不支持这么定义类名的,去掉就好了
答
void Update()
{
void OnGUI()
{
GUI.skin.label.fontSize = 100;
GUI.Label(new Rect(10, 10, Screen.width, Screen.height), "Hello World");
}
}
这两个方法嵌套在一起了,要前面一个方法花括号结束,再后一个方法的定义