Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:prototyping [2022/08/15 23:37] – [Player Prototyping] 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 331: | Line 335: | ||
| </ | </ | ||
| + | |||
| <code CSharp | ZombieCameraController Script> | <code CSharp | ZombieCameraController Script> | ||
| using System.Collections; | using System.Collections; | ||
| Line 429: | 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 438: | Line 443: | ||
| private void Awake() | private void Awake() | ||
| { | { | ||
| - | _rangeSensor = this.GetComponent< | ||
| _meshRenderer = this.GetComponent< | _meshRenderer = this.GetComponent< | ||
| _pool = FindObjectOfType< | _pool = FindObjectOfType< | ||
| Line 469: | 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 486: | 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. | ||
| - | </ | ||
| - | |||
| - | ====== NavMesh Agent AI ====== | ||
| - | |||
| - | {{ : | ||