Browse Source

Player Network Fix & Player Movement

feature/network
BanarD 2 years ago
parent
commit
c5e1eef405
  1. 7
      Assets/GameAssets/Prefabs/Network/Player.prefab.meta
  2. 54
      Assets/GameAssets/Scripts/PlayerMovement.cs

7
Assets/GameAssets/Prefabs/Network/Player.prefab.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ea740d57598a4f44b87d8a273e3e0687
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

54
Assets/GameAssets/Scripts/PlayerMovement.cs

@ -1,6 +1,4 @@
using System; using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.AI; using UnityEngine.AI;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
@ -8,37 +6,50 @@ using UnityEngine.EventSystems;
public class PlayerMovement : MonoBehaviour public class PlayerMovement : MonoBehaviour
{ {
[Header("Components")] [Header("Components")]
[SerializeField] private Player player;
[SerializeField] private NavMeshAgent agent; [SerializeField] private NavMeshAgent agent;
[SerializeField] private Animator animator;
private float lookRotationSpeed = 8f; private float lookRotationSpeed = 8f;
private bool isMoving = false;
void Awake() private bool prepareEvent = false;
{ private Action onDestinationReached;
agent = GetComponent<NavMeshAgent>();
animator = GetComponent<Animator>();
//input = new CustomActions(); private Animator animator => player.Animator;
//AssignInputs();
}
public void MoveTo(Vector3 point, Action action = null) public void MoveTo(Vector3 point, Action action = null)
{ {
agent.destination = point; agent.destination = point;
onDestinationReached = action;
}
//replace later public void MoveToBlock(Vector3 point, Action action = null)
{
InteractionManager.Instance.AddBlockReason("Moving");
MoveTo(point, () =>
{
action?.Invoke(); action?.Invoke();
} InteractionManager.Instance.RemoveBlockReason("Moving");
});
}
private void Update() private void Update()
{ {
if (!agent.pathPending && agent.remainingDistance > agent.stoppingDistance) isMoving = !agent.pathPending && agent.remainingDistance > agent.stoppingDistance;
if (isMoving)
{ {
prepareEvent = true;
FaceTarget(); FaceTarget();
} }
////SetAnimations(); else if (prepareEvent)
{
prepareEvent = false;
onDestinationReached?.Invoke();
}
SetAnimations();
} }
private void FaceTarget() private void FaceTarget()
@ -55,11 +66,10 @@ public class PlayerMovement : MonoBehaviour
agent.destination = transform.position; agent.destination = transform.position;
} }
//void SetAnimations() private void SetAnimations()
//{ {
// if (agent.velocity == Vector3.zero) if (!animator) return;
// { animator.Play(IDLE); }
// else animator.SetBool("Walking", agent.velocity != Vector3.zero);
// { animator.Play(WALK); } }
//}
} }
Loading…
Cancel
Save