---
title: "Scripts como componentes de comportamiento"
content_type: tutorial
url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento?language=es"
language: es
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/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es&version=4.x"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/scripts-as-behaviour-components.md?language=en"
  - name: "es"
    url: "https://learn.unity.com/tutorial/scripts-como-componentes-de-comportamiento.md?language=es"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/dong-zuo-konponentotoshitenosukuriputo.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/dongjag-keomponeonteuro-sayongdoeneun-seukeuribteu.md?language=ko"
  - name: "zh-cn"
    url: "https://learn.unity.com/tutorial/zuo-wei-xing-wei-zu-jian-de-jiao-ben.md?language=zh-cn"
last_updated: "2026-08-04T14:24:11.000Z"
---

# Scripts como componentes de comportamiento

Descubre qué son los scripts de Unity como componentes de comportamiento y aprende a crearlos y agregarlos a GameObjects.

¿Qué son los Scripts en Unity? Aprende sobre el componente de comportamiento que constituye un script de Unity y cómo crearlos y agregarlos a objetos.

Este tutorial está incluido en el proyecto _Scripting_ para principiantes.

Siguiente:  Variables y Funciones

[¿Quieres aprender más sobre este tópico? Conéctate con un experto en el desarrollo de videojuegos con Unity en una lección privada. ](https://livehelp.unity.com/?utm_campaign=connect_americas_acquisition_2019-LiveHelp-Launch&utm_content=LIVEHELP_LEARN-01-all&utm_medium=link&utm_source=learn&_ga=2.11666743.264336052.1572892345-1968629467.1563827889)

## 1. Scripts como componentes de comportamiento

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