private IEnumerator Start() { currentchance = Random.Range(minChance, maxChance); IMover mover = new MoverWithTranslate(this, moveSpeed); IMyAnimation animation = new CharacterAnimation(GetComponent <Animator>()); IFlip flip = new FlipWithTransform(this); IHealth health = GetComponent <IHealth>(); IAttacker attacker = GetComponent <IAttacker>(); IStopEdge stopEdge = GetComponent <IStopEdge>(); Idle idle = new Idle(mover, animation); Walk walk = new Walk(this, mover, animation, flip, patrols); ChasePlayer chasePlayer = new ChasePlayer(mover, flip, animation, stopEdge, IsPlayerRightSide); Attack attack = new Attack(_player.transform.GetComponent <IHealth>(), flip, animation, attacker, maxAttackTime, IsPlayerRightSide); TakeHit takeHit = new TakeHit(health, animation); Dead dead = new Dead(this, animation, () => { if (currentchance > Random.Range(0, 100)) { Instantiate(scorePrefab, transform.position, Quaternion.identity); } }); _stateMachine.AddTransition(idle, walk, () => idle.IsIdle == false); _stateMachine.AddTransition(idle, chasePlayer, () => DistanceFromMeToPlayer() < chaseDistance); _stateMachine.AddTransition(walk, chasePlayer, () => DistanceFromMeToPlayer() < chaseDistance); _stateMachine.AddTransition(chasePlayer, attack, () => DistanceFromMeToPlayer() < attackDistance); _stateMachine.AddTransition(walk, idle, () => !walk.IsWalking); _stateMachine.AddTransition(chasePlayer, idle, () => DistanceFromMeToPlayer() > chaseDistance); _stateMachine.AddTransition(attack, chasePlayer, () => DistanceFromMeToPlayer() > attackDistance); _stateMachine.AddAnyState(dead, () => health.IsDead); _stateMachine.AddAnyState(takeHit, () => takeHit.IsTakeHit); _stateMachine.AddTransition(takeHit, chasePlayer, () => takeHit.IsTakeHit == false); _stateMachine.SetState(idle); yield return(null); }