Switch-Case Statements and stateInfo.fullPathHash
Hi, I'm trying to use the switch statement combine with stateInfo.fullPathHash to define the cases
but for each case the console give this "error CS0150: A constant value is expected"
  using UnityEngine;
  using System.Collections;
  
  public class V_anim : MonoBehaviour {
  
  private Animator anim;
  private AnimatorStateInfo currentBaseState;
  
  static int Idle_SState = Animator.StringToHash ("Base Layer.Idle_Start");
  static int Idle_LState = Animator.StringToHash ("Base Layer.Idle_Loop");
  
  void Start () 
      {
          anim = GetComponent<Animator> ();
          if (anim.layerCount == 2)
          anim.SetLayerWeight (1,1);
  
      }
  
  void FixedUpdate ()
      {
      AnimDebugger();
      }
  
  void AnimDebugger()
      {
      AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo (0);
      
      switch (stateInfo.fullPathHash) 
          {
              case Idle_SState:
                  Debug.Log ("Idle_SState Running");
                  break;
              
              case Idle_LState:
                  Debug.Log("Idle_SState Running");
                  break;
              
              default:
                  Debug.Log("stateInfo.fullPathHash Variable Out of Range");
                  break;
          }
      }
 }
Just to clarify:
My final goal is not to use the Debug, I just use it to test my logic before using in a proper way,
Since I'm learning program yet, I didnt use any design patterns in the code, so sorry if its became confuse in anyway.
The error says that the value should be a constant but the "case" variable is declared as "Static Int" so I dont really understand why I cant use it.
I'm expecting some simple answer about it, I few like my lack of experience is sabotaging me.
Answer by Nikes · Mar 21, 2016 at 06:31 PM
I searched for the error and found that C# doesnt work like javascript, so I cant use variable as the case condition, next time I will search more about the error instead assuming wrongly what it means.
Your answer
 
 
             Follow this Question
Related Questions
switch case statment 0 Answers
how to start counting from the last index the script stop on? 2 Answers
StartCoroutine in a static member 0 Answers
Static bool 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                