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

Mouse ScrollWheel doesnt work

Discussion in 'Scripting' started by OkeyNik, Sep 19, 2017.

  1. OkeyNik

    OkeyNik

    Joined:
    Mar 14, 2017
    Posts:
    41
    I make a game from tutorial in YouTube, and make 100% the same. And yes, i allready attach "Player" to the "Main Camera". My problem is when i use my scroll it need to zoom in and zoom out, but nothing happen. So how can i fix it? In unity, browser, games and other programs scroll works...



    Here the code:
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class CameraController : MonoBehaviour {
    5. public Transform target;
    6. public Vector3 offset;
    7. public float zoomspeed = 4f;
    8. public float minZoom = 5f;
    9. public float maxZoom = 15f;
    10. private float currentZoom = 10f;
    11. public float pitch = 2f;
    12. void update ()
    13. {
    14. currentZoom -= Input.GetAxis ("Mouse ScrollWheel") * zoomspeed;
    15. currentZoom = Mathf.Clamp (currentZoom, minZoom, maxZoom);
    16. }
    17. void LateUpdate ()
    18. {
    19. transform.position = target.position - offset * currentZoom;
    20. transform.LookAt (target.position + Vector3.up * pitch);
    21. }
    22. }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Use code tags

    Is the value of currentZoom changing when you use your scroll? When you comment out line 15, again is the value of currentZoom changing when you use your scroll wheel. If not to both then you probably have messed up the Mouse ScrollWheel entry in your input manager. If the value of currentZoom is changing, is it not changing fast enough to be noticeable? For example if currentZoom goes from 10.0 to 10.0005 that would mean that it is seeing your scroll movement, but a movement of .0005 would probably be too small to notice in your game, so you'd need to increase zoomspeed significantly.

    If you're not even looking at the value of currentZoom, start outputting it and I'm sure it will help clear up what is wrong.