Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

#if does not work

Discussion in 'Unity Hub' started by unity_3WOEt9UWXYRsxw, Jul 21, 2019.

  1. unity_3WOEt9UWXYRsxw

    unity_3WOEt9UWXYRsxw

    Joined:
    Jul 21, 2019
    Posts:
    2
    Can anyone tell me why #if is ignored? Am I missing something to install?
    Code (CSharp):
    1. public class PlayrScript : MonoBehaviour
    2. {
    3.     private float playerSpeed = 200;
    4.     private float directionSpeed = 20;
    5.  
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.        
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.        
    16. #if Unity_editor
    17.  
    18.  
    19.         float moveOrizontal = Input.GetAxis("Horizontal");
    20.         //  Debug.Log("Input: " + moveOrizontal);
    21.  
    22.         transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(Mathf.Clamp(gameObject.transform.position.x + moveOrizontal, -2.5f, 2.5f), gameObject.transform.position.y, gameObject.transform.position.z), directionSpeed + Time.deltaTime);
    23.  
    24. #endif
    25.         GetComponent<Rigidbody>().velocity = Vector3.forward * playerSpeed * Time.deltaTime;
    26.     }
    27. }
    28.  
     
  2. Because you have posted in the wrong section of the forum. Go one up into the Editor support.

    BTW, because these things are case sensitive so try #if UNITY_EDITOR.
     
  3. unity_3WOEt9UWXYRsxw

    unity_3WOEt9UWXYRsxw

    Joined:
    Jul 21, 2019
    Posts:
    2
    OK it's the first time I didn't know. You're right but with the excuse that I didn't have the list of commands to insert for #if I thought it didn't work .... Thanks
     
  4. AbrahamDUnity

    AbrahamDUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    431
    Lurking-Ninja likes this.