動作コンポーネントとしてのスクリプト

Tutorial

Beginner

+0XP

5 mins

(73)

Unity Technologies

動作コンポーネントとしてのスクリプト

Unity のスクリプトとは?Unity の動作コンポーネントであるスクリプトについて、その作成方法とオブジェクトへのアタッチ方法をご紹介します。

本チュートリアルは Beginner Scripting プロジェクトに含まれています。

次のチュートリアルは:Variables and Functions

このトピックについて詳しく知りたいですか?エキスパートとオンラインで 1:1 レッスンを受けてみませんか?

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;
        }
    }
}

Complete this Tutorial