Attributes
확인 완료한 버전: 4.2
-
난이도: 중급
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.


Attributes
중급 Scripting
SpinScript
Code snippet
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));
}
}
#pragma strict
@Range(-100, 100)
public var speed : int = 0;
function Update ()
{
transform.Rotate(new Vector3(0, speed * Time.deltaTime, 0));
}
import UnityEngine
import System.Collections
public class SpinScript(MonoBehaviour):
[Range((-100), 100)]
public speed = 0
private def Update():
transform.Rotate(Vector3(0, (speed * Time.deltaTime), 0))
ColorScript
Code snippet
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class ColorScript : MonoBehaviour
{
void Start()
{
renderer.sharedMaterial.color = Color.red;
}
}
#pragma strict
@ExecuteInEditMode
function Start ()
{
renderer.sharedMaterial.color = Color.red;
}
import UnityEngine
import System.Collections
[ExecuteInEditMode]
public class ColorScript(MonoBehaviour):
private def Start():
renderer.sharedMaterial.color = Color.red