Can we add a script to the cursor?/Can you make an object follow cursor?

So, I made this script.

using UnityEngine;
using UnityEngine.Tilemaps;

public class ingameBuild : MonoBehaviour
{
    public Tile highlightTile;
    public Tilemap highlightMap;
    [SerializeField]
 

    // do late so that the player has a chance to move in update if necessary
    private void LateUpdate()
    {
        // get current grid location
        Vector3Int currentCell = highlightMap.WorldToCell(transform.position);   
        // if the position has changed
        if(Input.GetMouseButtonDown(1))
            highlightMap.SetTile(currentCell, highlightTile);
        }
    }

I can attach this code to an object. It doesn’t make the right thing. I either need to attach this to the cursor or make the object I attached this script exactly follow my cursor(with 0 delay, if you didn’t understand)

@aybarsmete1

If I got it right, you are thinking it upside down… just get the cursor position.

var cursorPos = Input.mousePosition;

Then use it to get your tile under cursor, instead of getting current cell with your player position.

I did it. Thanks

@aybarsmete1

Np. Drop a like to my post if it helped :wink:

1 Like

Tbh, I found it before you wrote, but I will drop a like for u :>