Attributes
Tutorial
·
intermediate
·
+10XP
·
5 mins
·
(1246)
Unity Technologies

Attributes allow you to attach additional behavior to the methods and variables you create. In this video you will learn the format of attributes as well as how to use the "Range" and "ExecuteInEditMode" attributes.
1. Attributes
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;
}
}