Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

274
Vistas
MouseX and MouseY axis not working Unity 2020.1.0f1

I have looked all over the internet and every question says this is fixed but I am experiencing some trouble. This is my code:

    private Vector3 startingPos;
    [HideInInspector]
    public bool empty;
    private bool hovered;
    private bool waitingForSeconds;
    private float timeSinceLastUpdate;

    private float scale = 1000f;

    [HideInInspector]
    public GameObject item;
    [HideInInspector]
    public Texture itemIcon;

    private GameObject player;
    private WeaponManager wm;
    private Inventory inventory;
    private GameObject[] craftable;

    public GameObject slotHolder;
    private Transform[] slots;
    
    private void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * scale * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * scale * Time.deltaTime;

        print(mouseX + " " + mouseY);

        if (item)
        {
            empty = false;
            itemIcon = item.GetComponent<Item>().icon;
        }
        else
        {
            empty = true;
            itemIcon = null;
        }

        this.GetComponent<RawImage>().texture = itemIcon;

        if (waitingForSeconds) timeSinceLastUpdate += Time.deltaTime;
        else timeSinceLastUpdate = 0f;

        if (timeSinceLastUpdate > 1f && item)
            transform.position = new Vector2(mouseX, mouseY);
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        if (hovered)
            waitingForSeconds = true;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        waitingForSeconds = false;
        if (hovered)
        {
            transform.position = startingPos;
            UseItem();
        }
        else
        {
            foreach (GameObject craftableItemSlot in craftable)
            {
                if (craftableItemSlot.GetComponent<CraftableItem>().hovered)
                {
                    if (craftableItemSlot.GetComponent<RawImage>().texture == null)
                    {
                        craftableItemSlot.GetComponent<RawImage>().texture = itemIcon;
                        itemIcon = null;
                        transform.position = startingPos;
                        craftableItemSlot.GetComponent<CraftableItem>().CheckForRequiredItems();
                        break;
                    }
                    else
                    {
                        transform.position = startingPos;
                    }
                }
            }

            // get the closest slot so we can switch positions
            Transform closestSlot = GetClosestSlot(slots);

            // switch positions
            transform.position = closestSlot.position;
            closestSlot.position = startingPos;
        }
    }

I have no idea what is going on because the mouseX and mouseY are sitting in the corner and it shouldn't be, when I print the values they are these small decimal numbers but I am multiplying by 1000. Am I using the wrong axis or can somebody tell me how to fix it because I am stuck.

Thank you!

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda