Skip to main content

This is an example of an enumenum being used in a switchswitch statement. I hope that this helps you.

using UnityEngine; 
using System.Collections; 

public class MyScriptFile : MonoBehaviour 
{
    // Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE}; 

    // The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        // Check the ActiveState variable 
        switch(ActiveState) 
        { 
            // Check one case
            case EnemyState.FIGHT: 
                {
                    //Perform fight code here
                    Debug.Log ("Entered fight state"); 
                }
                break; 

            // Check multiple cases at once
            case EnemyState.FLEE: 
            case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;

            // Default case when all other states fail 
            default: 
            {
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}

This is an example of an enum being used in a switch statement. I hope that this helps you.

using UnityEngine; 
using System.Collections; 

public class MyScriptFile : MonoBehaviour 
{
    // Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE}; 

    // The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        // Check the ActiveState variable 
        switch(ActiveState) 
        { 
            // Check one case
            case EnemyState.FIGHT: 
                {
                    //Perform fight code here
                    Debug.Log ("Entered fight state"); 
                }
                break; 

            // Check multiple cases at once
            case EnemyState.FLEE: 
            case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;

            // Default case when all other states fail 
            default: 
            {
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}

This is an example of an enum being used in a switch statement. I hope that this helps you.

using UnityEngine; 
using System.Collections; 

public class MyScriptFile : MonoBehaviour 
{
    // Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE}; 

    // The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        // Check the ActiveState variable 
        switch(ActiveState) 
        { 
            // Check one case
            case EnemyState.FIGHT: 
                {
                    //Perform fight code here
                    Debug.Log ("Entered fight state"); 
                }
                break; 

            // Check multiple cases at once
            case EnemyState.FLEE: 
            case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;

            // Default case when all other states fail 
            default: 
            {
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}
Normalised indentation; Added additional comments to clarify use of single and multiple case statements; grammar
Source Link
Philip Allgaier
  • 2.9k
  • 4
  • 26
  • 36

This is an example of an enumenum being used in a switchswitch statement. I hope that this helps you.

using UnityEngine; 
using System.Collections; 

public class MyScriptFile : MonoBehaviour 
{
    // Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE}; 

    // The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        // Check the ActiveState variable 
        switch(ActiveState) 
        { 
            // Check one case
            case EnemyState.FIGHT: 
                {
                    //Perform fight code here
                    Debug.Log ("Entered fight state"); 
                }
                break; 

            // Check multiple cases at once
            case EnemyState.FLEE: 
            case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;

            // Default case when all other states fail 
            default: 
            {
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}

This is example of an enum being used in a switch statement. I hope that this helps you.

using UnityEngine; 
using System.Collections; 

public class MyScriptFile : MonoBehaviour 
{
    // Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE}; 

    // The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        // Check the ActiveState variable 
        switch(ActiveState) 
        { 
            // Check one case
            case EnemyState.FIGHT: 
                {
                    //Perform fight code here
                    Debug.Log ("Entered fight state"); 
                }
                break; 

            // Check multiple cases at once
            case EnemyState.FLEE: 
            case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;

            // Default case when all other states fail 
            default: 
            {
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}

This is an example of an enum being used in a switch statement. I hope that this helps you.

using UnityEngine; 
using System.Collections; 

public class MyScriptFile : MonoBehaviour 
{
    // Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE}; 

    // The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        // Check the ActiveState variable 
        switch(ActiveState) 
        { 
            // Check one case
            case EnemyState.FIGHT: 
                {
                    //Perform fight code here
                    Debug.Log ("Entered fight state"); 
                }
                break; 

            // Check multiple cases at once
            case EnemyState.FLEE: 
            case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;

            // Default case when all other states fail 
            default: 
            {
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}
Normalised indentation; Added additional comments to clarify use of single and multiple case statements; grammar
Source Link

thisThis is example of an enum being used in a switch statement. I hope that helpthis helps you.

using UnityEngine; 
using System.Collections;  

public class MyScriptFile : MonoBehaviour  
{
    // Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE};  

    // The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        // Check the ActiveState variable 
        switch(ActiveState) 
        { 
            // Check one case
            case EnemyState.FIGHT: 
                {
                    //Perform fight code here
                    Debug.Log ("Entered fight state"); 
                }
                break; 

            // Check multiple cases at once
            case EnemyState.FLEE: 
            case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;
  
       default: 
     // Default case when all other states fail {
            default:  
   //Default case when all other states fail   {
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}

this is example of enum in switch statement I hope that help you

using UnityEngine; 
using System.Collections; 
public class MyScriptFile : MonoBehaviour {
    //Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE}; 
    //The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        //Check the ActiveState variable 
        switch(ActiveState) 
        { 
        case EnemyState.FIGHT: 
            {
                //Perform fight code here
                Debug.Log ("Entered fight state"); 
            }
            break; 
        case EnemyState.FLEE: 
        case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;
        default: 
             {
                //Default case when all other states fail 
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}

This is example of an enum being used in a switch statement. I hope that this helps you.

using UnityEngine; 
using System.Collections;  

public class MyScriptFile : MonoBehaviour  
{
    // Define possible states for enemy using an enum 
    public enum EnemyState {CHASE, FLEE, FIGHT, HIDE};  

    // The current state of enemy
    public EnemyState ActiveState = EnemyState.CHASE; 

    // Update is called once per frame 
    void Update ()
    {
        // Check the ActiveState variable 
        switch(ActiveState) 
        { 
            // Check one case
            case EnemyState.FIGHT: 
                {
                    //Perform fight code here
                    Debug.Log ("Entered fight state"); 
                }
                break; 

            // Check multiple cases at once
            case EnemyState.FLEE: 
            case EnemyState.HIDE: 
            { 
                //Flee and hide performs the same behaviour 
                Debug.Log ("Entered flee or hide state"); 
            } 
            break;
 
            // Default case when all other states fail 
            default:  
            {
                //This is used for the chase state 
                Debug.Log ("Entered chase state");
            } 
            break; 
        }
    }
}
Post Undeleted by Seyed Morteza Kamali
Post Deleted by Seyed Morteza Kamali
Source Link
Loading