Using enums as a function parameter

Hello everyone! I have a question about using an enum from one script as a parameter in a function in a nother script:

Here is my code for the script with the enum

using UnityEngine;
using System.Collections;

public class scr_cutscene_camera : MonoBehaviour 
{
    public enum CamZoom{none, zoom_in, zoom_out};
    public CamZoom myZoom;
   
    void Start()
    {
        myZoom = CamZoom.zoom_in;
    }
}

And here is the script I’d like to control it with in some functions

using UnityEngine;
using System.Collections;

public class scr_cutscene_controller : MonoBehaviour 
{
    public GameObject camera_ref; 
    scr_cutscene_camera srcc;

    void Start () 
    {
        srcc = camera_ref.GetComponent<scr_cutscene_camera>();
    }
   
    void Update () 
    {
        if (Input.GetKey(KeyCode.H))
        {
            srcc.myZoom = scr_cutscene_camera.CamZoom.zoom_in;
        }
        else
        {
            srcc.myZoom = scr_cutscene_camera.CamZoom.none;
        }
    }

    void CreateShot(enum CamZoom_variable)
    {
        srcc.myZoom = scr_cutscene_camera.CamZoom.CamZoom_variable;
    }
}

The problem is using a enum variable in the function. It isn’t working. I understand that enums aren’t really variables, and are kind of special, but I am not sure how to go about working around this. Thank you for your time!

The enum variable sent to the function should be defined as your CamZoom enum.
So your function should look like this:

void CreateShot(CamZoom CamZoom_variable)

but now that I think about it, your enum is inside your camera-scope, so you might even need to write:

void CreateShot(scr_cutscene_camera.CamZoom CamZoom_variable)

If you don’t want to have it scoped to your camera cutscene class, move it outside the camera cutscene scope, or just move it to a separate, empty script and paste in your enum there.

1 Like

Thank you so much! That second option worked perfectly!

Really appreciate the help Bro :slight_smile: