1. 创建一个Scene,并在里面创建一个GameObject。
    Unity脚本篇 - 变量和Inspector操作

  2. 编写一个脚本,并作为组件加载到GameObject上。
    Unity脚本篇 - 变量和Inspector操作

MainPlayer

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace VariablesAndTheInspector {

    public class MainPlayer : MonoBehaviour {
        public string myName;

        // Start is called before the first frame update
        private void Start() {
            Debug.Log("I am alive and my name is " + myName);
        }

        // Update is called once per frame
        private void Update() {
        }
    }
}
  1. 最后的文件结构是这样。
    Unity脚本篇 - 变量和Inspector操作

  2. 在控制台上看到log输出。
    Unity脚本篇 - 变量和Inspector操作

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
  • 2021-12-18
  • 2021-12-18
猜你喜欢
  • 2021-12-18
  • 2021-12-31
  • 2021-09-28
  • 2021-11-22
  • 2022-01-02
  • 2021-12-18
  • 2021-04-18
相关资源
相似解决方案