---
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=2019.3"
standalone_markdown_url: "https://learn.unity.com/tutorial/scripts-as-behaviour-components.md?language=en&version=2019.3"
next_title: "Variables and Functions"
next_url: "https://learn.unity.com/course/beginner-scripting/tutorial/variables-and-functions?language=en&version=2019.3"
next_markdown_url: "https://learn.unity.com/course/beginner-scripting/tutorial/variables-and-functions.md?language=en&version=2019.3"
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en&version=4.x"
last_updated: "2026-08-04T14:24:11.000Z"
---

# Scripts as Behaviour Components

Discover what Unity scripts are as behavior components and learn how to create and attach them to GameObjects.

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](https://learn.unity.com/project/beginner-gameplay-scripting).

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

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