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.

Question the input system with the mouse position works weird

Discussion in 'Input System' started by unity_005946E12C5F7D78583B, Aug 4, 2023.

  1. unity_005946E12C5F7D78583B

    unity_005946E12C5F7D78583B

    Joined:
    Dec 19, 2022
    Posts:
    35
    hi!, im trying to make an object follow the mouse with the new input system, my code looks like this:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5. public class mouse : MonoBehaviour
    6. {
    7.     public List<playerMovement> player = new List<playerMovement>();
    8.     Vector2 mouses;
    9.    public SpriteRenderer sprite;
    10.    public InputActionReference pointr;
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.        
    15.         mouses = pointr.action.ReadValue<Vector2>();
    16.         transform.position = mouses;
    17.  
    18.          //if (player[0].dragging == true)
    19.         // {
    20.           //  sprite.enabled = true;
    21.          //}
    22.         // else
    23.         // {
    24.          // sprite.enabled = false;
    25.         // }
    26.  
    27.  
    28.  
    29.        
    30.     }
    31. }
    but, for some reason, the object appears more on the upper right than on the mouse pointer itself, whats going on? ( im using the new input system for this
    )
     
  2. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    171
    Hi there,
    Are you using "DefaultInputActions" input action or you created a new one?
    And do you use "EventSystem" component in the scene?
     
  3. unity_005946E12C5F7D78583B

    unity_005946E12C5F7D78583B

    Joined:
    Dec 19, 2022
    Posts:
    35
    no im not using events, and yes im using a new input action that i made, its this
     

    Attached Files:

  4. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    171
    I think your problem looks like at this post.
    So, the problem is UI System references to DefaultInputActions, not what you are created.
    Try this : Add "EventSystem" in the scene and Change "Action Assets" of "Input System UI Input Module".
    But, if you do this, you have to manually assign the "Point", "Left Click" and others events manually.
     
  5. unity_005946E12C5F7D78583B

    unity_005946E12C5F7D78583B

    Joined:
    Dec 19, 2022
    Posts:
    35
    it... isnt working
     

    Attached Files:

  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,203
  7. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    171
    Yes As @spiney said you have to convert position and also you should add some log to check "pointr.action.ReadValue<Vector2>()" is working?