Initial Project Commit
This commit is contained in:
@@ -1,22 +1,39 @@
|
||||
using UnityEngine;
|
||||
using RPG.Movement;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace RPG.Combat
|
||||
{
|
||||
{
|
||||
public class Fighter : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float weaponRange = 2f;
|
||||
Transform target;
|
||||
private void Update()
|
||||
{
|
||||
if(target != null)
|
||||
if (target == null) return;
|
||||
if (!GetIsInRange())
|
||||
{
|
||||
GetComponent<Mover>().MoveTo(target.position);
|
||||
target = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
GetComponent<Mover>().Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private bool GetIsInRange()
|
||||
{
|
||||
return Vector3.Distance(transform.position, target.position) <= weaponRange;
|
||||
}
|
||||
|
||||
public void Attack(CombatTarget combatTarget)
|
||||
{
|
||||
target = combatTarget.transform;
|
||||
}
|
||||
public void Cancel()
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace RPG.Control
|
||||
if (hasHit)
|
||||
{
|
||||
if (moveAction.IsPressed())
|
||||
GetComponent<Mover>().MoveTo(hit.point);
|
||||
GetComponent<Mover>().StartMoveAction(hit.point);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using RPG.Combat;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -23,16 +24,24 @@ namespace RPG.Movement
|
||||
{
|
||||
UpdateAnimator();
|
||||
}
|
||||
public void StartMoveAction(Vector3 destination)
|
||||
{
|
||||
GetComponent<Fighter>().Cancel();
|
||||
MoveTo(destination);
|
||||
}
|
||||
|
||||
public void MoveTo(Vector3 destination)
|
||||
{
|
||||
navMeshAgent.destination = destination;
|
||||
navMeshAgent.isStopped = false;
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
navMeshAgent.isStopped = true;
|
||||
}
|
||||
|
||||
private void UpdateAnimator()
|
||||
{
|
||||
// This is your original code, which is correct!
|
||||
// It just uses the cached variables now.
|
||||
Vector3 velocity = navMeshAgent.velocity;
|
||||
Vector3 localVelocity = transform.InverseTransformDirection(velocity);
|
||||
float speed = localVelocity.z;
|
||||
|
||||
Reference in New Issue
Block a user