im trying to make an object follow the cursor, I did this before and it worked, but now it just doesnt work, im using this code, any ideas of what is happening?
using System.Collections;
using UnityEngine;
public class click : MonoBehaviour
{
private Vector3 mousePosition;
public float moveSpeed = 0.1f;
void Start()
{
//to prevent that object will move to zero at beginn.
mousePosition = transform.position;
}
void Update()
{
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
}
}
Double-click on the error. It will open the file that the error came from. It might also put the cursor at the offending line; if not, look for the line number in the console and go to that line.
Something in that line is null.
Without that information, it is very hard to tell you anything.