---
title: "Scripts as Behaviour Components"
content_type: tutorial
url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components?language=en"
language: en
container_type: course
container_title: "Beginner Scripting"
container_url: "https://learn.unity.com/course/beginner-scripting.md?language=en&version=2021.3"
standalone_markdown_url: "https://learn.unity.com/tutorial/scripts-as-behaviour-components.md?language=en&version=2021.3"
next_title: "Variables and Functions"
next_url: "https://learn.unity.com/course/beginner-scripting/tutorial/variables-and-functions?language=en&version=2021.3"
next_markdown_url: "https://learn.unity.com/course/beginner-scripting/tutorial/variables-and-functions.md?language=en&version=2021.3"
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2021.3"
supported_unity_versions:
  - name: "2021.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2021.3"
last_updated: "2026-10-07T22:05:15.000Z"
---

# Scripts as Behaviour Components

What are Scripts in Unity? Learn about the behavior component that is a Unity script, and how to Create and Attach them to objects.

Next: [Variables and Functions](https://learn.unity.com/tutorial/variables-and-functions?projectId=5c8920b4edbc2a113b6bc26a)

## 1. Scripts as Behaviour Components

[Video](http://www.youtube.com/watch?v=Z0Z7xc18CcA)

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