Search Unity

Question How can I disable editor Project Settings > Input Manager > Vertical > Alt Positive Button > w ?

Discussion in 'Input System' started by Chocolade, Nov 12, 2020.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    933


    I want to disable the w forward key pressing. And then to enable it back.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using TMPro;
    5. using UnityEngine;
    6. using UnityStandardAssets.Characters.ThirdPerson;
    7.  
    8. public class DistanceCheck : MonoBehaviour
    9. {
    10.    public GameObject distanceTarget;
    11.    public GameObject descriptionTextImage;
    12.    public TextMeshProUGUI text;
    13.  
    14.    private Animator anim;
    15.  
    16.    float timeElapsed = 0;
    17.    float lerpDuration = 3;
    18.    float startValue = 1;
    19.    float endValue = 0;
    20.    float valueToLerp = 0;
    21.  
    22.    // Opposite Direction
    23.    float timeElapsedOpposite = 0;
    24.    float lerpDurationOpposite = 3;
    25.    float startValueForOpposite = 0;
    26.    float endValueForOpposite = 1;
    27.    float valueToLerpOpposite = 0;  
    28.  
    29.    float angle;
    30.  
    31.    // Start is called before the first frame update
    32.    void Start()
    33.    {
    34.        angle = transform.eulerAngles.y;
    35.        anim = transform.GetComponent<Animator>();
    36.    }
    37.  
    38.    // Update is called once per frame
    39.    void Update()
    40.    {
    41.        var distance = Vector3.Distance(transform.position, distanceTarget.transform.position);
    42.        angle = transform.eulerAngles.y;
    43.        if (distance >= 61f && angle < 180)
    44.        {
    45.            if (timeElapsed < lerpDuration)
    46.            {
    47.                valueToLerp = Mathf.Lerp(startValue, endValue, timeElapsed / lerpDuration);
    48.                anim.SetFloat("Forward", valueToLerp);
    49.                timeElapsed += Time.deltaTime;
    50.            }
    51.            anim.SetFloat("Forward", valueToLerp);
    52.            // Here to disable the w key
    53.            timeElapsedOpposite = 0;
    54.            descriptionTextImage.SetActive(true);
    55.            text.text = "I can't move that far by foot. I need to find some transportation to move any further.";
    56.        }
    57.        else
    58.        {
    59.            text.text = "";
    60.            descriptionTextImage.SetActive(false);
    61.        }
    62.  
    63.        // Get the angle:
    64.        
    65.  
    66.        if (angle > 180f && distance >= 61f)
    67.        {
    68.            if (timeElapsedOpposite < lerpDurationOpposite)
    69.            {
    70.                valueToLerpOpposite = Mathf.Lerp(startValueForOpposite, endValueForOpposite, timeElapsedOpposite / lerpDurationOpposite);
    71.                anim.SetFloat("Forward", valueToLerpOpposite);
    72.                timeElapsedOpposite += Time.deltaTime;
    73.            }
    74.            anim.SetFloat("Forward", valueToLerpOpposite);
    75.            // Here to enable back the w key
    76.            timeElapsed = 0;
    77.        }
    78.    }
    79. }
    80.  
    I marked using // in the script the two places where I want to disable the w key and where to enable it back. but I'm not sure how to reference to it.