Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!