Project
Beginner Gameplay Scripting
Scripts as Behavior Components
Tutorial
Beginner
20 Mins
Unity Technologies
Overview
You have completed 0% of this Tutorial.
1.
Scripts as Behaviour Components
Summary
What are Scripts in Unity? Learn about the behavior component that is a Unity script, and how to Create and Attach them to objects.
This tutorial is included in the Beginner Scripting project.
Next: Variables and Functions
Language
English
Recommended Unity Versions
4.1 and Above
1.
Scripts as Behaviour Components
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; } } }

Woohoo! You nailed this tutorial.
Continue rocking your Beginner Gameplay Scripting project.
Next Step:
Variables and Functions
Tutorial
Beginner
10 Mins
Unity Technologies