UnityEngine;
using System.Collections;
public class LevelScript : MonoBehaviour
{
public int experience;
public int Level
{
get{ return experience / 750; }}//确保exprience只读
}
接着,在Editor文件夹下创建一个LevelScriptEditor,编辑脚本如下:
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(LevelScript))]
public class LevelScriptEditor : Editor
{
public override void OnInspectorGUI()//重写OnInspectorGUI方法
{
LevelScript myTarget = (LevelScript)target;