-
创建一个Scene,并在里面创建一个GameObject。

-
编写一个脚本,并作为组件加载到GameObject上。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace CreateAndUsingScripts {
public class MainPlayer : MonoBehaviour {
// Start is called before the first frame update
private void Start() {
Debug.Log("I am alive!");
}
// Update is called once per frame
private void Update() {
}
}
}
-
最后的文件结构是这样。

-
在控制台上看到log输出。

参考:https://docs.unity3d.com/Manual/CreatingAndUsingScripts.html
本文介绍如何在Unity中创建场景及游戏对象,并为游戏对象编写及附加脚本。使用C#编写了一个简单的脚本,该脚本会在游戏启动时输出一条消息。

被折叠的 条评论
为什么被折叠?



