I have a c# script to make my player move towards the mouse but I need it to rotate to face the mouse. I have never dealt with these types of controls before and I’ve been trying for a long time to figure it out.
Here is my script:
using UnityEngine;
using System.Collections;
public class playerController : MonoBehaviour
{
private Vector3 _target;
public Camera Camera;
public bool FollowMouse;
public bool ShipAccelerates;
public float ShipSpeed = 2.0f;
void Start()
{
}
public void OnEnable()
{
if (Camera == null)
{
throw new System.InvalidOperationException("Camera not set");
}
}
public void Update()
{
if (FollowMouse || Input.GetMouseButton(0))
{
_target = Camera.ScreenToWorldPoint(Input.mousePosition);
_target.y = 0;
}
var delta = ShipSpeed * Time.deltaTime;
if (ShipAccelerates)
{
delta *= Vector3.Distance(transform.position, _target);
}
transform.position = Vector3.MoveTowards(transform.position, _target, delta);
}
thank you so much for helping!