add live in city

This commit is contained in:
2022-11-18 11:48:19 +02:00
parent d89f0b6777
commit 5947e907c0
43 changed files with 119238 additions and 1064 deletions
+37 -27
View File
@@ -42,13 +42,18 @@ public class PlayerManager : MonoBehaviour
public Stat tvItem = new Stat("Tv Item", 1500, 1);
public Stat laptopItem = new Stat("Laptop Item", 3000, 1);
public NavMeshAgent player;
public Animator playerAnimator;
public Camera playerCamera;
public ParticleSystem targetDest;
public bool allowMovement = true;
[SerializeField]
public NavMeshAgent _navAgent;
[SerializeField]
public Animator _animator;
[SerializeField]
private Camera _camera;
[SerializeField]
public ParticleSystem _targetDest;
public bool allowMovement = true;
private States _state;
private Vector3 _groundDeltaPosition;
private void OnEnable()
{
@@ -64,6 +69,7 @@ public class PlayerManager : MonoBehaviour
void Start()
{
allowMovement = true;
_navAgent.updatePosition = false;
}
// Update is called once per frame
void Update()
@@ -72,31 +78,35 @@ public class PlayerManager : MonoBehaviour
{
if (Input.GetMouseButton(0))
{
Ray myRay = playerCamera.ScreenPointToRay(Input.mousePosition);
targetDest.Stop();
if (Physics.Raycast(myRay, out RaycastHit hit))
_targetDest.Stop();
if (Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, 100))
{
var pos=hit.point;
var pos = hit.point;
pos.y += 0.2f;
targetDest.transform.position = pos;
player.SetDestination(pos);
targetDest.Play();
_targetDest.transform.position = pos;
_navAgent.SetDestination(pos);
_targetDest.Play();
}
}
}
else
{
player.SetDestination(player.transform.position);
player.velocity = Vector3.zero;
}
if (player.velocity != Vector3.zero)
{
playerAnimator.SetBool("IsWalking", true);
}
else if (player.velocity == Vector3.zero)
{
playerAnimator.SetBool("IsWalking", false);
}
var worldDeltaPosition=_navAgent.nextPosition- transform.position;
_groundDeltaPosition.x=Vector3.Dot(transform.right, worldDeltaPosition);
_groundDeltaPosition.y = Vector3.Dot(transform.forward, worldDeltaPosition);
Vector2 velocity = (Time.deltaTime > 1e-5f) ? _groundDeltaPosition / Time.deltaTime : Vector2.zero;
var shouldMove = velocity.magnitude > 0.025f && _navAgent.remainingDistance > _navAgent.radius;
_state = shouldMove ? States.Walking : States.Idle;
_animator.SetBool("Move", shouldMove);
_animator.SetFloat("velY", velocity.y);
}
private void OnAnimatorMove()
{
transform.position = _navAgent.nextPosition;
}
public void DecreaseEnergy()
@@ -116,13 +126,13 @@ public class PlayerManager : MonoBehaviour
{
_state = States.Sleeping;
allowMovement = false;
playerAnimator.SetBool("IsSleeping", true);
_animator.SetBool("IsSleeping", true);
}
if (energy.Value >= 100 && _state == States.Sleeping)
{
_state = States.Idle;
allowMovement = false;
playerAnimator.SetBool("IsSleeping", false);
_animator.SetBool("IsSleeping", false);
}
}