Search Unity

mouse wheel working, but character is not moving

Discussion in 'Editor & General Support' started by maubar, Nov 17, 2015.

  1. maubar

    maubar

    Joined:
    May 27, 2015
    Posts:
    128
    hi ,
    I need on a part of my game, the player walks back and forth, moving the mouse wheel.
    How can i tell to unity, to move my character with the mouse wheel.
    the will is working because when i move the wheel, prints number 1 positive and number 2 negative.
    but the chracter is not moving.

    what i made wrong with this code?
    thanks so much for any help !

    Code (JavaScript):
    1. var speed = 2.5;
    2.  
    3. function Update () {
    4.  
    5. if(Input.GetAxis("Mouse ScrollWheel") > 0)
    6.     {
    7.      transform.position = transform.TransformDirection(Vector3.forward * speed); // if don't working try without speed
    8.      print(1);
    9.     }
    10. else if(Input.GetAxis("Mouse ScrollWheel") < 0)
    11.     {
    12.      transform.position = transform.TransformDirection(Vector3.forward * speed); // if don't working try without speed
    13.      print(2);
    14.     }
    15.  
    16. }
    on console print 1 and 2 ..... that means wheel is working.
    but the character is not moving.
    please help

    mousewheel.jpg
     
    Last edited: Nov 18, 2015
  2. maubar

    maubar

    Joined:
    May 27, 2015
    Posts:
    128
    solved .....

    if some body need it.

    Code (JavaScript):
    1. var speed : float = 3.0;
    2.  
    3.     function Update ()
    4.     {
    5.         var controller : CharacterController = GetComponent.<CharacterController>();
    6.  
    7.         var forward : Vector3 = transform.TransformDirection(Vector3.forward);
    8.         var curSpeed : float = speed * Input.GetAxis ("Mouse ScrollWheel");
    9.         controller.SimpleMove(forward * curSpeed);
    10.     }