属性

使用属性可以将其他行为附加到所创建的方法和变量。在本视频中,您将学习属性的格式以及如何使用“Range”和“ExecuteInEditMode”属性。

 

SpinScript

using UnityEngine;
using System.Collections;

public class SpinScript : MonoBehaviour 
{
    [Range(-100, 100)] public int speed = 0;

    void Update () 
    {
        transform.Rotate(new Vector3(0, speed * Time.deltaTime, 0));
    }
}

ColorScript

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class ColorScript : MonoBehaviour 
{
    void Start()
    {
        renderer.sharedMaterial.color = Color.red;
    }
}

 

posted @ 2020-12-16 15:02  Luohanhui  阅读(60)  评论(0编辑  收藏  举报