
動作コンポーネントとしてのスクリプト
Tutorial
Beginner
+0XP
5 mins
(73)
Unity Technologies

Unity のスクリプトとは?Unity の動作コンポーネントであるスクリプトについて、その作成方法とオブジェクトへのアタッチ方法をご紹介します。
本チュートリアルは Beginner Scripting プロジェクトに含まれています。
次のチュートリアルは:Variables and Functions
Languages available:
1. 動作コンポーネントとしてのスクリプト
using UnityEngine;
using System.Collections;
public class ExampleBehaviourScript : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
GetComponent<Renderer> ().material.color = Color.red;
}
if (Input.GetKeyDown(KeyCode.G))
{
GetComponent<Renderer>().material.color = Color.green;
}
if (Input.GetKeyDown(KeyCode.B))
{
GetComponent<Renderer>().material.color = Color.blue;
}
}
}