---
title: "Instrucción Switch"
content_type: tutorial
url: "https://learn.unity.com/tutorial/instruccion-switch?language=es"
language: es
difficulty: beginner
duration_minutes: 5
unity_version:
  - "4.x"
supported_unity_versions:
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/instruccion-switch.md?language=es&version=4.x"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/switch-statements.md?language=en"
  - name: "es"
    url: "https://learn.unity.com/tutorial/instruccion-switch.md?language=es"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/switch-wen.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/switch-mun.md?language=ko"
  - name: "zh-cn"
    url: "https://learn.unity.com/tutorial/switch-yu-ju.md?language=zh-cn"
last_updated: "2026-08-04T14:21:59.000Z"
---

# Instrucción Switch

Aprende a escribir y usar instrucciones switch en C# para comparar un valor con varias constantes en tus scripts de Unity.

Las estructuras Switch funcionan como condicionales de optimización. Son muy útiles cuando quieres comparar un valor único con una serie de constantes. En este video aprenderás cómo escribirlas y cómo usarlas.

Este tutorial está incluido en el proyecto [_Scripting_ para principiantes. ](https://learn.unity.com/project/scripting-para-principiantes)

Previo: Invocar

Este es el final del proyecto. ¡Felicidades!

## 1. Estructuras Switch

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

## **ConversationScript**

```csharp
using UnityEngine;
using System.Collections;

public class ConversationScript : MonoBehaviour 
{
    public int intelligence = 5;
    
    
    void Greet()
    {
        switch (intelligence)
        {
        case 5:
            print ("Why hello there good sir! Let me teach you about Trigonometry!");
            break;
        case 4:
            print ("Hello and good day!");
            break;
        case 3:
            print ("Whadya want?");
            break;
        case 2:
            print ("Grog SMASH!");
            break;
        case 1:
            print ("Ulg, glib, Pblblblblb");
            break;
        default:
            print ("Incorrect intelligence level.");
            break;
        }
    }
}
```
