Added sitting animation
This commit is contained in:
+22
-15
@@ -1,5 +1,4 @@
|
||||
using Assets.Scripts.Actions.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
@@ -9,9 +8,6 @@ public enum TaskStatus { Waiting, InProgress, Complete };
|
||||
public enum ActionStates { Idle, Walking, Sleeping, Sitting };
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
public event EventHandler<OnPlayerMovesEventArgs> OnPlayerMoves;
|
||||
|
||||
|
||||
public static Player Instance { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
@@ -37,6 +33,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
if (Instance != null)
|
||||
{
|
||||
Debug.Log("There's more than one player instance");
|
||||
@@ -65,15 +62,23 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
if (_currentTask != null)
|
||||
{
|
||||
if (_currentTask.Status == TaskStatus.Waiting)
|
||||
Debug.Log($"Current task {_currentTask.Task}");
|
||||
switch (_currentTask.Task)
|
||||
{
|
||||
case Tasks.Move:
|
||||
OnPlayerMoves?.Invoke(this, new OnPlayerMovesEventArgs() { PointToMove = _currentTask.Position });
|
||||
_navAgent.SetDestination(_currentTask.Position);
|
||||
_navAgent.SetDestination(_currentTask.TagretObject._playerArrivePoint.position);
|
||||
_currentTask.UpdateStatus(MoveToPoint());
|
||||
break;
|
||||
case Tasks.Interact:
|
||||
_currentTask.UpdateStatus(InteractWithObject(_currentTask.Interactable));
|
||||
if (pathComplete(_currentTask.TagretObject._playerArrivePoint.position))
|
||||
_currentTask.UpdateStatus(InteractWithObject(_currentTask.TagretObject));
|
||||
else
|
||||
{
|
||||
AddTask(new PlayerTasks(Tasks.Move, _currentTask.TagretObject));
|
||||
AddTask(_currentTask);
|
||||
_currentTask = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -97,12 +102,17 @@ public class Player : MonoBehaviour
|
||||
_animator.SetFloat(WALK_VELOCITY, velocity.y);
|
||||
}
|
||||
|
||||
return pathComplete() ? TaskStatus.Complete : TaskStatus.InProgress;
|
||||
return pathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
|
||||
}
|
||||
|
||||
private bool pathComplete()
|
||||
public void Rotate(Vector3 target)
|
||||
{
|
||||
if (Vector3.Distance(_navAgent.destination, _navAgent.transform.position) <= _navAgent.radius)
|
||||
Quaternion rotation = Quaternion.LookRotation(target);
|
||||
transform.rotation = rotation;
|
||||
}
|
||||
private bool pathComplete(Vector3 destination)
|
||||
{
|
||||
if (Vector3.Distance(destination, _navAgent.transform.position) <= _navAgent.radius)
|
||||
{
|
||||
if (!_navAgent.hasPath || _navAgent.velocity.sqrMagnitude == 0f)
|
||||
{
|
||||
@@ -126,19 +136,16 @@ public class Player : MonoBehaviour
|
||||
{
|
||||
case ActionStates.Idle:
|
||||
_animator.SetBool(WALK, false);
|
||||
break;
|
||||
case ActionStates.Walking when _currentState == ActionStates.Sitting:
|
||||
_animator.SetBool(SIT_DOWN, false);
|
||||
_animator.SetBool(SIT_DOWN, true);
|
||||
_animator.SetBool(WALK, true);
|
||||
|
||||
break;
|
||||
case ActionStates.Walking:
|
||||
_animator.SetBool(WALK, true);
|
||||
break;
|
||||
case ActionStates.Sleeping:
|
||||
break;
|
||||
break;
|
||||
case ActionStates.Sitting:
|
||||
_animator.SetBool(SIT_DOWN, true);
|
||||
break;
|
||||
}
|
||||
_currentState = newState;
|
||||
|
||||
Reference in New Issue
Block a user