#if does not work

Can anyone tell me why #if is ignored? Am I missing something to install?

public class PlayrScript : MonoBehaviour
{
    private float playerSpeed = 200;
    private float directionSpeed = 20;

    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
       
#if Unity_editor


        float moveOrizontal = Input.GetAxis("Horizontal");
        //  Debug.Log("Input: " + moveOrizontal);

        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);

#endif
        GetComponent<Rigidbody>().velocity = Vector3.forward * playerSpeed * Time.deltaTime;
    }
}

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.

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

You’re welcome.

For further reference: https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

Thank you for informing users @ :smile:

1 Like