i want the player change the position following the mouse’s position, something like this Quick Tip: Smoothly Move an Entity to the Position of the Mouse but only on the x axis.
After almost two hours trying i finally made it. I leave the code here if anyone is interested.
using UnityEngine;
using System.Collections;
public class Mover : MonoBehaviour {
public float speed;
private Rigidbody2D player;
// Use this for initialization
void Start () {
player = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
float moveHorizontal = Input.GetAxis ("Mouse X");
Vector2 move = new Vector2 (moveHorizontal, 0);
player.AddForce (move * speed);
}
}