Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:prototyping [2022/08/12 00:43] – [NPC Agro prototype] admin | wiki:prototyping [2022/08/15 23:52] (current) – [Prototyping Zombie Minigame] admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Prototyping Zombie Minigame ====== | ====== Prototyping Zombie Minigame ====== | ||
| + | {{ : | ||
| + | <file| Prototyping?> | ||
| + | This is the way I make function of models before I make it official. | ||
| + | </ | ||
| ====== Player Prototyping ====== | ====== Player Prototyping ====== | ||
| Line 14: | Line 18: | ||
| using System; | using System; | ||
| using Sirenix.OdinInspector; | using Sirenix.OdinInspector; | ||
| + | using UnityEngine.Events; | ||
| + | using HighlightPlus; | ||
| public class ZombiePlayerController : MonoBehaviour | public class ZombiePlayerController : MonoBehaviour | ||
| Line 33: | Line 39: | ||
| [BoxGroup(" | [BoxGroup(" | ||
| public float groundGravity = 1f; | public float groundGravity = 1f; | ||
| + | [BoxGroup(" | ||
| + | public float runStamina = 15f; | ||
| [BoxGroup(" | [BoxGroup(" | ||
| Line 46: | Line 54: | ||
| [ShowInInspector] | [ShowInInspector] | ||
| private float _righDirection; | private float _righDirection; | ||
| + | [BoxGroup(" | ||
| + | [ShowInInspector] | ||
| + | private float _velocity; | ||
| + | [BoxGroup(" | ||
| + | [ShowInInspector] | ||
| + | private float _storedRunStamina; | ||
| private CharacterController _characterController; | private CharacterController _characterController; | ||
| + | private ZombieHealth _zombieHealth; | ||
| + | private HighlightEffect _highlight; | ||
| + | |||
| + | [HideInEditorMode] | ||
| + | public UnityEvent< | ||
| + | |||
| + | [HideInEditorMode] | ||
| + | public UnityEvent onPlayerDied; | ||
| private void Awake() | private void Awake() | ||
| { | { | ||
| Initialization(); | Initialization(); | ||
| + | } | ||
| + | |||
| + | private void Start() | ||
| + | { | ||
| + | _storedRunStamina = runStamina; | ||
| + | _zombieHealth.sendEventOnMinusHealth.AddListener(ReceivedEventOnPlayerHit); | ||
| + | SendEventToUI(); | ||
| } | } | ||
| Line 57: | Line 86: | ||
| { | { | ||
| _characterController = this.GetComponent< | _characterController = this.GetComponent< | ||
| + | _zombieHealth = this.GetComponent< | ||
| + | _highlight = this.GetComponent< | ||
| } | } | ||
| private void Update() | private void Update() | ||
| { | { | ||
| + | |||
| + | if (_zombieHealth.IsDead()) | ||
| + | { | ||
| + | onPlayerDied.Invoke(); | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | _velocity = GetVelocity(); | ||
| + | |||
| SetRightFowardDirection(); | SetRightFowardDirection(); | ||
| Line 94: | Line 134: | ||
| var desiredMoveDirection = (forward * verticalAxis + right * horizontalAxis).normalized * movementSpeed; | var desiredMoveDirection = (forward * verticalAxis + right * horizontalAxis).normalized * movementSpeed; | ||
| - | if(Input.GetKey(KeyCode.LeftShift)) | + | |
| + | |||
| + | | ||
| { | { | ||
| return desiredMoveDirection * movementSprintSpeed; | return desiredMoveDirection * movementSprintSpeed; | ||
| Line 101: | Line 143: | ||
| return desiredMoveDirection; | return desiredMoveDirection; | ||
| } | } | ||
| + | |||
| + | private void SprintController() | ||
| + | { | ||
| + | SendEventToUI(); | ||
| + | |||
| + | if(GetVelocity() > 5) | ||
| + | { | ||
| + | runStamina -= Time.deltaTime; | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | if (runStamina < _storedRunStamina && GetVelocity() == 0) runStamina += Time.deltaTime; | ||
| + | } | ||
| private float _jumpDuration = 0; | private float _jumpDuration = 0; | ||
| Line 159: | Line 214: | ||
| public float GetVelocity() => _characterController.velocity.magnitude; | public float GetVelocity() => _characterController.velocity.magnitude; | ||
| #endregion | #endregion | ||
| - | } | ||
| - | </ | + | #region EVENT |
| - | + | private void InitializeEvent() | |
| - | + | ||
| - | <code CSharp | ZombiePlayerCharacterAnimationController Script> | + | |
| - | using Animancer; | + | |
| - | using System.Collections; | + | |
| - | using System.Collections.Generic; | + | |
| - | using UnityEngine; | + | |
| - | + | ||
| - | public class ZombiePlayerCharacterAnimationController : MonoBehaviour | + | |
| - | { | + | |
| - | [SerializeField] private AnimancerComponent _Animancer; | + | |
| - | [SerializeField] private ClipTransition _idle; | + | |
| - | [SerializeField] private ClipTransition _moveFoward; | + | |
| - | [SerializeField] private ClipTransition _moveBackward; | + | |
| - | [SerializeField] private ClipTransition _moveRight; | + | |
| - | [SerializeField] private ClipTransition _moveLeft; | + | |
| - | [SerializeField] private ClipTransition _runFoward; | + | |
| - | [SerializeField] private ClipTransition _runBackward; | + | |
| - | [SerializeField] private ClipTransition _runRight; | + | |
| - | [SerializeField] private ClipTransition _runLeft; | + | |
| - | + | ||
| - | [SerializeField] private AudioSource _parentAudioSource; | + | |
| - | [SerializeField] private AudioClip _walkStepSoud; | + | |
| - | [SerializeField] private AudioClip _runStepSound; | + | |
| - | + | ||
| - | private ZombiePlayerController playerController; | + | |
| - | + | ||
| - | private void Start() | + | |
| { | { | ||
| - | | + | |
| - | | + | |
| } | } | ||
| - | private void Update() | + | private void SendEventToUI() |
| { | { | ||
| - | | + | |
| - | + | ||
| - | MovementAnimationPlayByVelocity(); | + | |
| } | } | ||
| - | private void MovementAnimationPlayByVelocity() | + | private void ReceivedEventOnPlayerHit() |
| { | { | ||
| - | | + | |
| - | { | + | |
| - | PlayMovementByAnimation(_runFoward, | + | |
| - | + | ||
| - | } | + | |
| - | else | + | |
| - | { | + | |
| - | PlayMovementByAnimation(_moveFoward, | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | private void PlayMovementByAnimation(ClipTransition foward, ClipTransition backward, ClipTransition right, ClipTransition left, AudioClip stepSound) | + | |
| - | { | + | |
| - | if (playerController.GetFowardDiretion() > 1f) | + | |
| - | { | + | |
| - | var anim = _Animancer.Play(foward); | + | |
| - | + | ||
| - | anim.Events.Add(0.30f, | + | |
| - | anim.Events.Add(0.80f, | + | |
| - | } | + | |
| - | + | ||
| - | if (playerController.GetFowardDiretion() < -1f) | + | |
| - | { | + | |
| - | var anim = _Animancer.Play(backward); | + | |
| - | + | ||
| - | anim.Events.Add(0.30f, | + | |
| - | anim.Events.Add(0.80f, | + | |
| - | } | + | |
| - | + | ||
| - | if (playerController.GetRightDirection() > 1f) | + | |
| - | { | + | |
| - | var anim = _Animancer.Play(right); | + | |
| - | + | ||
| - | anim.Events.Add(0.30f, | + | |
| - | anim.Events.Add(0.80f, | + | |
| - | } | + | |
| - | + | ||
| - | if (playerController.GetRightDirection() < -1f) | + | |
| - | { | + | |
| - | var anim = _Animancer.Play(left); | + | |
| - | + | ||
| - | anim.Events.Add(0.30f, | + | |
| - | anim.Events.Add(0.80f, | + | |
| - | } | + | |
| } | } | ||
| + | # endregion | ||
| } | } | ||
| Line 352: | Line 335: | ||
| </ | </ | ||
| + | |||
| <code CSharp | ZombieCameraController Script> | <code CSharp | ZombieCameraController Script> | ||
| using System.Collections; | using System.Collections; | ||
| Line 450: | Line 434: | ||
| public float bulletSpeed = 25f; | public float bulletSpeed = 25f; | ||
| public ParticleSystem bulletCollideParticle; | public ParticleSystem bulletCollideParticle; | ||
| - | + | public float bulletDamage = 10; | |
| - | | + | |
| private MeshRenderer _meshRenderer; | private MeshRenderer _meshRenderer; | ||
| private Pool _pool; | private Pool _pool; | ||
| Line 459: | Line 443: | ||
| private void Awake() | private void Awake() | ||
| { | { | ||
| - | _rangeSensor = this.GetComponent< | ||
| _meshRenderer = this.GetComponent< | _meshRenderer = this.GetComponent< | ||
| _pool = FindObjectOfType< | _pool = FindObjectOfType< | ||
| Line 490: | Line 473: | ||
| canMove = false; | canMove = false; | ||
| bulletCollideParticle.Play(); | bulletCollideParticle.Play(); | ||
| + | |||
| + | if(_rangeSensor.GetNearestDetection().TryGetComponent(out ZombieHealth zombieHealth)) | ||
| + | { | ||
| + | zombieHealth.MinusHealth(bulletDamage); | ||
| + | } | ||
| StartCoroutine(DespawnGameObject(bulletCollideParticle.main.duration)); | StartCoroutine(DespawnGameObject(bulletCollideParticle.main.duration)); | ||
| Line 507: | Line 495: | ||
| } | } | ||
| - | </ | ||
| - | ====== NPC Prototyping ====== | ||
| - | |||
| - | {{ : | ||
| - | |||
| - | <code CSharp | ZombieNpcMovingNashMeshController Script> | ||
| - | using Sirenix.OdinInspector; | ||
| - | using System.Collections; | ||
| - | using System.Collections.Generic; | ||
| - | using UnityEngine; | ||
| - | using UnityEngine.AI; | ||
| - | |||
| - | public class ZombieNpcMovingNashMeshController : MonoBehaviour | ||
| - | { | ||
| - | [BoxGroup(" | ||
| - | [SerializeField] private string d_tranfsormName; | ||
| - | [BoxGroup(" | ||
| - | [SerializeField] private float d_remainingDistance; | ||
| - | [BoxGroup(" | ||
| - | [SerializeField] private float d_velocity; | ||
| - | |||
| - | [BoxGroup(" | ||
| - | [BoxGroup(" | ||
| - | |||
| - | [SerializeField] private List< | ||
| - | private int checkPointIndex = 0; | ||
| - | private int currentIndex = 0; | ||
| - | |||
| - | private NavMeshAgent _navMeshAgent; | ||
| - | private ZombieAnimationController _zombieAnimationController; | ||
| - | |||
| - | [SerializeField] private Transform movePositionTransform; | ||
| - | |||
| - | private void Awake() | ||
| - | { | ||
| - | _navMeshAgent = GetComponent< | ||
| - | _zombieAnimationController = GetComponent< | ||
| - | _navMeshAgent.updateRotation = false; | ||
| - | } | ||
| - | |||
| - | private void Update() | ||
| - | { | ||
| - | | ||
| - | if (_navMeshAgent.remainingDistance <= _navMeshAgent.stoppingDistance) | ||
| - | { | ||
| - | |||
| - | currentIndex = checkPointIndex == _checkPoint.Count - 1 ? checkPointIndex = 0 : checkPointIndex += 1; | ||
| - | | ||
| - | } | ||
| - | |||
| - | MoveAgentToDestination(_checkPoint[currentIndex]); | ||
| - | } | ||
| - | |||
| - | private void MoveAgentToDestination(Transform transform) | ||
| - | { | ||
| - | _navMeshAgent.destination = transform.position; | ||
| - | |||
| - | d_tranfsormName = transform.gameObject.name; | ||
| - | d_remainingDistance = _navMeshAgent.remainingDistance; | ||
| - | d_velocity = _navMeshAgent.velocity.magnitude; | ||
| - | |||
| - | if (_navMeshAgent.velocity.sqrMagnitude > Mathf.Epsilon) | ||
| - | { | ||
| - | this.transform.rotation = Quaternion.LookRotation(_navMeshAgent.velocity.normalized); | ||
| - | } | ||
| - | } | ||
| - | |||
| - | [Button] | ||
| - | public void MakeCharacterWalk() | ||
| - | { | ||
| - | _navMeshAgent.speed = _walkSpeed; | ||
| - | } | ||
| - | |||
| - | [Button] | ||
| - | public void MakeCharacterRunning() | ||
| - | { | ||
| - | _navMeshAgent.speed = _runSpeed; | ||
| - | } | ||
| - | |||
| - | [Button] | ||
| - | public void MakeCharacterPunch() | ||
| - | { | ||
| - | _zombieAnimationController.PlayAction(_zombieAnimationController.attack); | ||
| - | } | ||
| - | } | ||
| </ | </ | ||
| - | |||
| - | <code CSharp | ZombieAnimationController Script> | ||
| - | using Animancer; | ||
| - | using Sirenix.OdinInspector; | ||
| - | using System.Collections; | ||
| - | using System.Collections.Generic; | ||
| - | using UnityEngine; | ||
| - | using UnityEngine.AI; | ||
| - | |||
| - | public class ZombieAnimationController : MonoBehaviour | ||
| - | { | ||
| - | private AnimancerComponent _Animancer; | ||
| - | [SerializeField] public ClipTransition idle; | ||
| - | [SerializeField] public ClipTransition moveFoward; | ||
| - | [SerializeField] public ClipTransition runFoward; | ||
| - | [SerializeField] public ClipTransition attack; | ||
| - | [SerializeField] private AvatarMask _baseBody; | ||
| - | [SerializeField] private AvatarMask _upperBody; | ||
| - | |||
| - | private AnimancerLayer _baseLayer; | ||
| - | private AnimancerLayer _upperBodyLayer; | ||
| - | |||
| - | //private CharacterController _characterController; | ||
| - | private NavMeshAgent _navMeshAgent; | ||
| - | |||
| - | private void Awake() | ||
| - | { | ||
| - | Initialization(); | ||
| - | |||
| - | InitializationAnim(); | ||
| - | } | ||
| - | |||
| - | private void Initialization() | ||
| - | { | ||
| - | // | ||
| - | _navMeshAgent = GetComponent< | ||
| - | _Animancer = GetComponentInChildren< | ||
| - | } | ||
| - | |||
| - | private void InitializationAnim() | ||
| - | { | ||
| - | _baseLayer = _Animancer.Layers[0]; | ||
| - | _upperBodyLayer = _Animancer.Layers[1]; | ||
| - | |||
| - | _baseLayer.SetMask(_baseBody); | ||
| - | _upperBodyLayer.SetMask(_upperBody); | ||
| - | attack.Events.OnEnd = OnActionEnd; | ||
| - | } | ||
| - | |||
| - | private void Update() | ||
| - | { | ||
| - | // | ||
| - | if (_navMeshAgent.velocity.magnitude > 1f) | ||
| - | { | ||
| - | _baseLayer.Play(moveFoward, | ||
| - | } | ||
| - | |||
| - | //if (_characterController.velocity.magnitude > 2f) | ||
| - | if(_navMeshAgent.velocity.magnitude > 2f) | ||
| - | { | ||
| - | _baseLayer.Play(runFoward, | ||
| - | } | ||
| - | } | ||
| - | |||
| - | bool _canBePlayed = true; | ||
| - | public void PlayAction(ClipTransition clip) | ||
| - | { | ||
| - | if (!_canBePlayed) return; | ||
| - | |||
| - | _upperBodyLayer.Play(clip); | ||
| - | |||
| - | StartCoroutine(PlayActionDelay(clip.Clip.length)); | ||
| - | } | ||
| - | |||
| - | private IEnumerator PlayActionDelay(float length) | ||
| - | { | ||
| - | _canBePlayed = false; | ||
| - | yield return new WaitForSeconds(length); | ||
| - | _canBePlayed = true; | ||
| - | } | ||
| - | |||
| - | private void OnActionEnd() | ||
| - | { | ||
| - | _upperBodyLayer.StartFade(0, | ||
| - | } | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | |||
| - | ====== NPC Agro prototype ====== | ||
| - | |||
| - | {{ : | ||
| - | |||
| - | |||
| - | <file | Agro > | ||
| - | There' | ||
| - | - outer layer when zombie heard shoots they will go agro, and this layer player need to escape from it to stop the agro. | ||
| - | - first inner when player move close to zombie. | ||
| - | - nearest layer for zombie detect when can it hit player. | ||
| - | </ | ||