using System.Collections; using System.Collections.Generic; using UnityEngine; public class Character : SyncBase { public float MovementSpeed = 5.0f; public CharacterController CharacterController; private Vector3 MovementDirection = new Vector3(); /// /// Moves the character in the wanted direction. /// /// Movement direction. public void Move(Vector3 Direction) { if (!Direction.Equals(MovementDirection)) { MovementDirection = Direction.normalized; } } /// /// Stops the player from moving. /// public void Stop() { if (Moving()) { MovementDirection = new Vector3(); } } public bool Moving() { return MovementDirection.sqrMagnitude != 0; } private void FixedUpdate() { CharacterController.Move(MovementDirection * MovementSpeed * Time.fixedDeltaTime); } }