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. 56
      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:

56
Assets/GameAssets/Scripts/PlayerMovement.cs

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