public void OnDeath() { AI.OnDeath(); Animation.Die(); // Spawn some money Debug.Log("Spawning monies"); BattleManager.instance.map.SpawnMoneyOnTile(new Vector2Int(xPos, zPos), UnityEngine.Random.Range(MinMoneySpawned, MaxMoneySpawned)); }
public void Die() { onDie?.Invoke(); _animation.Die(); _navAgent.ResetPath(); _navAgent.velocity = Vector3.zero; GetComponentInChildren <Collider>().isTrigger = true; SwitchState(States.Dead); _canRotate = false; }
public virtual void killEnemy() //my enemies are all the same size, so the reassignment of size and offset can be the same for all enemies, otherwise it would have to be an abstract function { if (Alive) //workaround since this method gets called multiple times for some reason { player.addScore(1000); //player gets 1000 points for killing enemy lvlMnger.decreaseEnemy(); } Alive = false; Debug.Log("enemy killed"); Vector2 collSize = _collider.size; Vector2 collOffset = _collider.offset; collSize.y = 0.01f; //wasn't sure how to disable collision, so this is a workaround collOffset.y = 0.1f; _collider.size = collSize; _collider.offset = collOffset; _enemyAnim.Die(); _rigid.gravityScale = 1; //makes enemy not float if he gets rolled midair }
protected virtual void StateMachine() { #region STATE CONFIGS /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// var idle = new State <Inputs>(CommonState.IDLE); var onSigth = new State <Inputs>(CommonState.ONSIGHT); var pursuit = new State <Inputs>(CommonState.PURSUIRT); var searching = new State <Inputs>(CommonState.SEARCHING); var attack = new State <Inputs>(CommonState.ATTACKING); var die = new State <Inputs>(CommonState.DIE); StateConfigurer.Create(idle) .SetTransition(Inputs.ON_LINE_OF_SIGHT, onSigth) .SetTransition(Inputs.DIE, die) .Done(); StateConfigurer.Create(onSigth) .SetTransition(Inputs.PROBOCATED, pursuit) .SetTransition(Inputs.OUT_LINE_OF_SIGHT, searching) .SetTransition(Inputs.DIE, die) .Done(); StateConfigurer.Create(pursuit) .SetTransition(Inputs.OUT_LINE_OF_SIGHT, searching) .SetTransition(Inputs.IN_RANGE_TO_ATTACK, attack) .SetTransition(Inputs.DIE, die) .Done(); StateConfigurer.Create(searching) .SetTransition(Inputs.TIME_OUT, idle) .SetTransition(Inputs.ON_LINE_OF_SIGHT, pursuit) .SetTransition(Inputs.DIE, die) .Done(); StateConfigurer.Create(attack) .SetTransition(Inputs.OUT_RANGE_TO_ATTACK, pursuit) .SetTransition(Inputs.OUT_LINE_OF_SIGHT, searching) .SetTransition(Inputs.DIE, die) .Done(); StateConfigurer.Create(die).Done(); /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// #endregion #region STATES /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// //****************** //*** IDLE //****************** idle.OnEnter += x => { myRb.velocity = Vector2.zero; anim.Idle(); }; idle.OnUpdate += () => { Deb_Estado = "IDLE"; if (LineOfSight()) { Debug.Log("Line of sigth"); SendInputToFSM(Inputs.ON_LINE_OF_SIGHT); } CheckBullet(); }; //****************** //*** ON SIGHT //****************** onSigth.OnEnter += x => { feedbackstate.SetStateGraphic(preset.sprite_OnSight); }; onSigth.OnUpdate += () => { Deb_Estado = "ON SIGTH"; if (LineOfSight()) { LookSmooth(); OnSight_CountDownForProbocate(); } else { timer_to_probocate = 0; SendInputToFSM(Inputs.OUT_LINE_OF_SIGHT); } }; onSigth.OnExit += x => { feedbackstate.SetStateGraphic(); }; //****************** //*** PURSUIT //****************** pursuit.OnEnter += x => { anim.Run(); }; pursuit.OnUpdate += () => { Deb_Estado = "PURSUIT"; if (LineOfSight()) { FollowPlayer(); if (IsInDistanceToAttack()) { SendInputToFSM(Inputs.IN_RANGE_TO_ATTACK); } } else { timer_to_probocate = 0; SendInputToFSM(Inputs.OUT_LINE_OF_SIGHT); } }; pursuit.OnExit += x => { myRb.velocity = Vector2.zero; }; //****************** //*** SEARCH //****************** searching.OnEnter += x => { anim.Walk(); feedbackstate.SetStateGraphic(preset.sprite_Search); }; searching.OnUpdate += () => { CheckBullet(); Deb_Estado = "SEARCH"; if (LineOfSight()) { SendInputToFSM(Inputs.ON_LINE_OF_SIGHT); } else { transform.Rotate(0, 0, 2); OutSight_CountDownForIgnore(); } }; searching.OnExit += x => { feedbackstate.SetStateGraphic(); }; //****************** //*** ATTACK //****************** attack.OnUpdate += () => { Deb_Estado = "ATTACK"; if (LineOfSight()) { LookSmooth(); if (IsInDistanceToAttack()) { anim.Attack(); Attack(); } else { SendInputToFSM(Inputs.OUT_RANGE_TO_ATTACK); } } else { SendInputToFSM(Inputs.OUT_LINE_OF_SIGHT); } }; attack.OnExit += x => { timer = 0; }; //****************** //*** DEATH //****************** die.OnEnter += x => { Deb_Estado = "DEATH"; canMove = false; gameObject.GetComponent <Collider2D>().enabled = false; anim.Die(); lifebar.Off(); del_to_remove(this); }; /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// #endregion _myFsm = new EventFSM <Inputs>(idle); }