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. Dismiss Notice

Menu Buttons Not Moving Much Further and Unsmooth

Discussion in 'Scripting' started by Davidbillmanoy, Jul 12, 2014.

  1. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    Hi! my menu buttons are not moving much further and are not smooth(I mean the buttons go directly to the distance not actually moving). Can you help me?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CarSelect : MonoBehaviour {
    5.     void OnMouseEnter() {
    6.         transform.Translate(Vector3.right);
    7.     }
    8.     void OnMouseExit() {
    9.         transform.Translate (Vector3.left);
    10.     }
    11. }
    12.  
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    you should multiply with Time.deltaTime. and preferably also some speed factor variable for control.
     
  3. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    What about the distance?
     
  4. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    what is it that you want the buttons to do?
     
  5. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    When i hover on the mouse, the buttons will go to the position with movement speed.
     
  6. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    which position? Vector3.right is not "really" a position... is the same as Vector3(1, 0, 0);
     
  7. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CarSelect : MonoBehaviour
    5. {
    6.     void OnMouseEnter() {
    7.         transform.Translate(4,0,0);
    8.     }
    9.     void OnMouseExit() {
    10.         transform.Translate (-4,0,0);
    11.     }
    12. }
    13.  
    I will never make a menu with sliding buttons horizontally on the mouse.
     
    Last edited: Jul 14, 2014
  8. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    just use an other function then translate if the have to stop. what you are missing now is the same as my previous answer.
    just use movetowards.
     
  9. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    Oh for pete's sake. Look it up:

    The moving buttons while on the mouse are in 0:11.
     
  10. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    ...? so whats the problem? are you waiting for me to write it for you?
    all you need is right here in the reference??
    if you can't convert what's written there to what you need, you shouldn't be coding imo...

    as for transform.Translate you need one of the axis in your vector3 to increment otherwise there is no translation...
     
  11. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    What axis?

    I did it:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SelectMouseEnter : MonoBehaviour
    5. {
    6.     public Transform target;
    7.     public float speed;
    8.  
    9.     void OnMouseEnter() {
    10.         float step = speed * Time.deltaTime;
    11.         transform.position = Vector3.MoveTowards(transform.position, target.position, step);
    12.     }
    13. }
    But the button still not moving in speed.
     
    Last edited: Jul 14, 2014
  12. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    did you set your speed to other then 0? does your button have a collider?
    with translate in your case the x axis.
     
  13. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    1. I did
    2. It doesn't.
     
  14. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    if it doesn't have a collider the Mouse functions won't work... these are in short raycasts so they need collider to detect.