Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Start() an Enum? is call Twice ?

Discussion in 'Scripting' started by Viperia, Oct 12, 2015.

  1. Viperia

    Viperia

    Joined:
    Feb 17, 2014
    Posts:
    9
    HI,

    I try to catch the value from an enum. The enum is selected in the inspector.
    My code:
    //The enum List
    public enum EndingMode {StayOn, MouseOver, MouseExit, userCall}
    public EndingMode endingMethode;
    //just to test
    private string zeta;

    void Start(){
    zeta = endingMethode.ToString ();
    if(zeta =="StayOn")
    Debug.Log ("stay");
    if(zeta == "MouseOver")
    Debug.Log ("mouseover");
    if(zeta == "MouseExit")
    Debug.Log ("mouseexit");
    if(zeta == "userCall")
    Debug.Log ("useCall");
    }

    Result in console:
    if i select "mouseOver" in inspector:
    mouseover
    UnityEngine.Debug:Log(Object)
    stay
    UnityEngine.Debug:Log(Object)

    if i select "StayOn" in inspetor:
    stay
    UnityEngine.Debug:Log(Object)
    stay
    UnityEngine.Debug:Log(Object)

    etc.
    The first value of the enum ("stayOn") is always selected at the end of the start method.
    I got the same problem with a custom Inspector.

    what's wrong with my code?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    I'm guessing you have this script attached to an extra object in your scene.

    If you can't find it, try this:
    Code (csharp):
    1. Debug.Log("thing", gameObject);
    Then clicking on the log message will highlight the object in the scene.
     
  3. Viperia

    Viperia

    Joined:
    Feb 17, 2014
    Posts:
    9
    ... kill me...
    the scipt was attached to tha camera..(i don't know when i have do that..)

    you are awesome!!!!