unity 2d object follow mouse
using UnityEngine;
using System.Collections;
public class MouseMove2D : MonoBehaviour {
private Vector3 mousePosition;
public float moveSpeed = 0.1f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(1)) {
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
}
}
}