|
4 | 4 |
|
5 | 5 | public class SelectableCharacterEntity : MonoBehaviour
|
6 | 6 | {
|
| 7 | + [SerializeField] private float _walkSpeed = 1; |
| 8 | + [SerializeField] private string _weaponAnim; |
| 9 | + [SerializeField] private Vector3 _destination; |
| 10 | + [SerializeField] private Vector3 _destEulerAngles; |
7 | 11 | [SerializeField] private CharSelectionInfoPackage _characterInfo;
|
| 12 | + [SerializeField] private bool _walking = false; |
8 | 13 |
|
9 |
| - public CharSelectionInfoPackage CharacterInfo { get { return _characterInfo; } set { _characterInfo = value; } } |
| 14 | + private CharacterController _characterController; |
| 15 | + private BaseAnimationController _baseAnimationController; |
| 16 | + |
| 17 | + public CharSelectionInfoPackage CharacterInfo { get { return _characterInfo; } set { _characterInfo = value; } } |
| 18 | + |
| 19 | + public string WeaponAnim { get { return _weaponAnim; } set { _weaponAnim = value; } } |
| 20 | + |
| 21 | + private void Awake() { |
| 22 | + _characterController = GetComponent<CharacterController>(); |
| 23 | + _baseAnimationController = GetComponent<BaseAnimationController>(); |
| 24 | + _destination = transform.position; |
| 25 | + } |
| 26 | + |
| 27 | + private void Update() { |
| 28 | + float ditanceToDestination = Vector3.Distance(_destination, transform.position); |
| 29 | + if(ditanceToDestination > 0.05f) { |
| 30 | + if(!_walking) { |
| 31 | + StartWalking(); |
| 32 | + } |
| 33 | + |
| 34 | + transform.LookAt(new Vector3(_destination.x, transform.position.y, _destination.z)); |
| 35 | + _characterController.Move(transform.forward.normalized * Time.deltaTime * _walkSpeed); |
| 36 | + } else if(_walking) { |
| 37 | + StopWalking(); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + private void StartWalking() { |
| 42 | + _walking = true; |
| 43 | + _baseAnimationController.SetBool("wait_" + WeaponAnim, false); |
| 44 | + _baseAnimationController.SetBool("walk_" + WeaponAnim, true); |
| 45 | + } |
| 46 | + |
| 47 | + private void StopWalking() { |
| 48 | + _walking = false; |
| 49 | + _baseAnimationController.SetBool("walk_" + WeaponAnim, false); |
| 50 | + _baseAnimationController.SetBool("wait_" + WeaponAnim, true); |
| 51 | + transform.eulerAngles = _destEulerAngles; |
| 52 | + } |
| 53 | + |
| 54 | + public void SetDestination(Logongrp destination) { |
| 55 | + Vector3 pawnPosition = new Vector3(destination.X, destination.Y, destination.Z); |
| 56 | + _destination = VectorUtils.ConvertPosToUnity(pawnPosition); |
| 57 | + _destEulerAngles = new Vector3(0, 360.00f * destination.Yaw / 65536, 0); |
| 58 | + } |
10 | 59 | }
|
0 commit comments