Mam kod działający na zasadzie kontrolera i swojego rodzaju napędu(przesyłam oby dwa kody).Chciałbym aby kod pozwalał na poruszanie się przez trzymanie myszy a nie tylko klikanie.
Kontroler
if (Input.GetMouseButtonDown(1))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100,movementMask))
{
motor.MoveToPoint(hit.point);
RemoveFocus();
}
"Napęd"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class PlayerMotor : MonoBehaviour
{
Transform target;
NavMeshAgent agent;
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if(target != null)
{
agent.SetDestination(target.position);
FaceTarget();
}
}
public void MoveToPoint(Vector3 point)
{
agent.SetDestination(point);
}
public void FolloTarget(Inter newTarget)
{
agent.stoppingDistance = newTarget.radius * .8f;
agent.updateRotation = false;
target = newTarget.transform;
}
public void StopFollowTarget()
{
agent.stoppingDistance = 0f;
agent.updateRotation = true;
target = null;
}
void FaceTarget()
{
Vector3 direction = (target.position - transform.position).normalized;
Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0f, direction.z));
transform.rotation = Quaternion.Slerp(transform.rotation,lookRotation,Time.deltaTime*5f);
}
}