protected override void Awake() { base.Awake(); SetGizmoColor(Color.blue); _cc = GetComponent <CharacterController>(); _stat = GetComponent <SlimeStat>(); _anim = GetComponentInChildren <Animator>(); _playercc = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterController>(); _playerTransform = _playercc.transform; SlimeState[] stateValues = (SlimeState[])System.Enum.GetValues(typeof(SlimeState)); foreach (SlimeState s in stateValues) { System.Type FSMType = System.Type.GetType("Slime" + s.ToString()); SlimeFSMState state = (SlimeFSMState)GetComponent(FSMType); if (null == state) { state = (SlimeFSMState)gameObject.AddComponent(FSMType); } _states.Add(s, state); state.enabled = false; } }
public void AttackCheck() { if (target == null) { return; } SlimeStat targetStat = target.GetComponent <SlimeStat>(); targetStat.ApplyDamage(stat); }
public void ApplyDamage(SlimeStat from) { hp -= from.attackRate; if (hp <= 0) { manager.SetDead(); if (lastHitBy == null) { lastHitBy = from; } from.NotifyDead(); } }
private void Awake() { slani = GetComponentInChildren <Animator>(); stat = GetComponent <SlimeStat>(); states.Add(SlimeState.IDLE, GetComponent <SlimeIDLE>()); states.Add(SlimeState.PATROL, GetComponent <SlimePATROL>()); states.Add(SlimeState.CHASE, GetComponent <SlimeCHASE>()); states.Add(SlimeState.ATTACK, GetComponent <SlimeATTACK>()); states.Add(SlimeState.DEAD, GetComponent <SlimeDEAD>()); scc = GetComponent <CharacterController>(); sight = GetComponentInChildren <Camera>(); PlayerCc = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterController>(); }
public static void JJMove(CharacterController scc, Vector3 destination, SlimeStat stat) { Transform transform = scc.transform; JJRotate(transform, destination, stat); Vector3 deltaMove = Vector3.MoveTowards( transform.position, destination, stat.slimeSpeed * Time.deltaTime) - transform.position; deltaMove.y = -stat.slimeFall * Time.deltaTime; scc.Move(deltaMove); }
public static void JJRotate(Transform transform, Vector3 destination, SlimeStat stat) { // B-A는 A에서 B로 향하는 벡터. Vector3 dir = destination - transform.position; dir.y = 0.0f; if (dir != Vector3.zero) { transform.rotation = Quaternion.RotateTowards( transform.rotation, Quaternion.LookRotation(dir), stat.slimeRotat * Time.deltaTime ); } }
public static void JJMove(CharacterController scc, Transform target, SlimeStat stat) { Transform transform = scc.transform; JJMove(scc, target.position, stat); }