Input Issue

    float zZoom = 40f;
    float zoomSpeed = 10f;

    void Update()
    {
        Debug.Log("Zooming ready");
        Zoom();
    }
    void Zoom()
    {
       bool zoomActive = Input.GetButtonDown(KeyCode.Q.ToString());

       if (zoomActive == true)
       {

        float zOffset = zZoom * Time.deltaTime * zoomSpeed;
        float rawZPos = transform.localPosition.z + zOffset;
        Debug.Log("Zooming");
       }   
    }

It is giving me an error that the Q button isn’t configured. Why is that?

Hi,

Try to remove ToString() from KeyCode.Q.ToString().


See also:

If I do that it gives me an error.

So I thought adding .ToString() would fix it.

Test GetKeyDown. GetButtonDown refers to a string in the Input Manager.

Ohh! I got confused between Key and Button! Okay, thanks!

Now what I want it to do is zoom in (z-axis) when I click Q using the same code we used for the player movement (Argon Assult)

How do you suppose I do that?

With more than 250,000 students to support, I’m afraid I do not have time to help with problems that are outside the scope of this course. I would suggest to add a few Debug.Logs to your code to see what values the user input returns. Then process the data as you need it for your solution. Also please feel free to ask our helpful community of students over on our Discord chat server.

Okay, I understand. Thank you so much for your help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms