- Home /
Issue with moving the custom cursor sprite
Hello, I am still relatively new to Unity and I need help with the coding the custom cursor.
The issue is that the sprite attached with the CursorFollow C# script attached, does not move along with the mouse. The cursor I am making is not a generic cursor which could be implemented by simply adjusting the player setting in Unity.
Here is the code written below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CursorFollow : MonoBehaviour
{
private SpriteRenderer rend;
public Sprite selectedCursor;
public Sprite normalCursor;
void Start()
{
Cursor.visible = false;
rend = GetComponent<SpriteRenderer>();
}
void Update()
{
Vector2 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = cursorPos;
if (Input.GetMouseButtonDown(0)){
rend.sprite = selectedCursor;
} else if (Input.GetMouseButtonUp(0)) {
rend.sprite = normalCursor;
}
}
}
Please tell me tell me the issue or how this code can be adjusted so that it can move along the mouse. Every other property that is written in and implemented seems to be working fine.
Your answer
Follow this Question
Related Questions
mouse Input Instantiate 0 Answers
Bring object on hover closer 0 Answers
Camera.main.ScreenToWorldPoint not working 0 Answers
Rotate sprite to face direction of movement 1 Answer
Cursor.LockState = CursorLockMode.Locked doesn‘t works。 0 Answers