Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

In help setting up the mouse wheel

Discussion in 'Getting Started' started by sadsack, Oct 31, 2020.

  1. sadsack

    sadsack

    Joined:
    May 27, 2015
    Posts:
    156
    I am am working on rts camera movement. I am using the wheel of the mouse move into the map and away from the map. The error I am getting is the mouse wheel is not set up. I been looking all over to find how to set it up. If anyone know of a tut.or know how to do it and want to help let me know.
    I am using unity 18.3 on window 7. I looked at the mouse wheel in the game setting and it as all blanks.
    That is it
    Thank You
    Renny
     
  2. sadsack

    sadsack

    Joined:
    May 27, 2015
    Posts:
    156
    Here is my script and a photo of the mouse wheel in the game setup.

    wheel.png
    Code (CSharp):
    1. sing System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class InputManager : MonoBehaviour
    6. {
    7.     public float panSpeed;
    8.     public float rotateSpeed;
    9.     public float rotateAmount;
    10.  
    11.  
    12.     private Quaternion rotation;
    13.  
    14.     private float panDetect = 15f;
    15.  
    16.     private float minHeight = 10f;
    17.     private float maxHeight = 100f;
    18.  
    19.     // Start is called before the first frame update
    20.     void Start()
    21.     {
    22.         rotation = Camera.main.transform.rotation;
    23.     }
    24.  
    25.     // Update is called once per frame
    26.     void Update()
    27.     {
    28.         MoveCamera();
    29.         RotateCamera();
    30.         if (Input.GetKeyDown(KeyCode.Space))
    31.         {
    32.             Camera.main.transform.rotation = rotation;
    33.  
    34.         }
    35.  
    36.  
    37.  
    38.  
    39.     } void MoveCamera()
    40.     {
    41.  
    42.         float moveX = Camera.main.transform.position.x;
    43.         float moveY = Camera.main.transform.position.y;
    44.         float moveZ = Camera.main.transform.position.z;
    45.         float xPos = Input.mousePosition.x;
    46.         float yPos = Input.mousePosition.y;
    47.  
    48.         if (Input.GetKey(KeyCode.A) || xPos > 0 && xPos < panDetect)
    49.         {
    50.             moveX -= panSpeed;
    51.  
    52.         }
    53.         else if (Input.GetKey(KeyCode.D) || xPos < Screen.width && xPos > Screen.width - panDetect)
    54.         {
    55.             moveX += panSpeed;
    56.         }
    57.         if (Input.GetKey(KeyCode.W) || yPos < Screen.height && xPos > Screen.height - panDetect)
    58.         {
    59.             moveZ += panSpeed;
    60.         }
    61.         else if (Input.GetKey(KeyCode.S) || yPos > 0 && yPos < panDetect)
    62.         {
    63.             moveZ -= panSpeed;
    64.         }
    65.         //moveY -= Input.GetAxis("Mouse Scrollwheel") * (panSpeed * 20);
    66.         moveY = Mathf.Clamp(moveY, minHeight, maxHeight);
    67.         Vector3 newPos = new Vector3(moveX, moveY, moveZ);
    68.         Camera.main.transform.position = newPos;
    69.     }
    70.  
    71.     void RotateCamera()
    72.     {
    73.  
    74.         Vector3 origin = Camera.main.transform.eulerAngles;
    75.         Vector3 destination = origin;
    76.  
    77.         if (Input.GetMouseButtonDown(2))
    78.         {
    79.             destination.x -= Input.GetAxis("Mouse Y") * rotateAmount;
    80.             destination.y += Input.GetAxis("Mouse X") * rotateAmount;
    81.  
    82.         }
    83.         if (destination != origin)
    84.         {
    85.             Camera.main.transform.eulerAngles = Vector3.MoveTowards(origin, destination, Time.deltaTime * rotateSpeed);
    86.         }
    87.     }
    88. }
    89.        
    90.  
    91.  
    92.  
    Thank you
    Renny
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Your code is looking for "Mouse Scrollwheel" but the axis actually set up is "Mouse ScrollWheel".
     
  4. sadsack

    sadsack

    Joined:
    May 27, 2015
    Posts:
    156
    I will look at that, not sure what you are talking about.
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    It's all in your screenshots above. The Input Manager:
    upload_2020-11-1_7-49-57.png
    ...and your code:
    upload_2020-11-1_7-50-13.png

    You must be precise when programming (and aware that most things are case-sensitive). "Mouse ScrollWheel" and "Mouse Scrollwheel" are not the same.
     
  6. sadsack

    sadsack

    Joined:
    May 27, 2015
    Posts:
    156
    I see, I all ready dump the code. I am going to have to start from the beginning.
    Thank you both very much.
    Renny
     
  7. sadsack

    sadsack

    Joined:
    May 27, 2015
    Posts:
    156
    I try everything, over 9 tutorial on using Mouse Scrollwheel on my game compute. I try a new mouse. I get the same error Mouse Scrollwheel not set up. I took 5 or 6 of the tutorial. and put on my laptop and ran them on unity 2020.1. They all worked on my laptop and unity 2020.1. I uninstall unity 18.3 and re in stall it. Still not one of the Mouse Scrollwheel Tut. will work on unity 18.3. So, what else can I do????
    renny
     
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Did you fix the capitalization error? Perhaps you should again post screen shots of your Input Manager and your code.