// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator anim, AnimatorStateInfo stateInfo, int layerIndex) { cb = anim.GetComponentInParent <script_childBehaviour>(); rb = anim.GetComponentInParent <Rigidbody>(); mc = anim.GetComponentInChildren <script_maskController>(); mc.free(); rb.isKinematic = false; bool cond = cb.asthmatic; if (cond) { nextState = childState.idle; } switch (nextState) { case childState.idle: anim.SetTrigger("idle"); break; case childState.walk: anim.SetTrigger("walk"); break; case childState.run: cb.startRunning(true); anim.SetTrigger("run"); break; } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) //{ // //} // OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator anim, AnimatorStateInfo stateInfo, int layerIndex) { //cb = anim.GetComponent<script_childBehaviour>(); bool cond = cb.asthmatic; if (cond) { cb.saved = true; nextState = childState.idle; script_gameController.winGame(); } cb.state = nextState; }
public void changeState(childState s, bool runType = false) { if (state != childState.die) { state = s; switch (s) { case childState.idle: rb.isKinematic = false; anim.SetTrigger(trigger_idle); break; case childState.walk: rb.isKinematic = false; anim.SetTrigger(trigger_walk); break; case childState.run: startRunning(runType); rb.isKinematic = false; anim.SetTrigger(trigger_run); break; case childState.die: rb.isKinematic = true; anim.SetTrigger(trigger_die); break; case childState.checkMask: checkedMask = true; rb.isKinematic = true; time = 0f; Vector3 from = Vector3.ProjectOnPlane(transform.forward, Vector3.up).normalized; Vector3 to = Vector3.ProjectOnPlane(script_gameController.character.transform.position - transform.position, Vector3.up).normalized; angleToRot = Vector3.SignedAngle(from, to, Vector3.up); anim.SetTrigger(trigger_checkMask); break; case childState.showFace: rb.isKinematic = true; anim.SetTrigger(trigger_showFace); break; } //Debug.Log(s); } }