// Start is called before the first frame update public void Start() { rb = GetComponent <Rigidbody2D>(); GetComponent <Damageable>().damageAction += (n) => rb.AddForce(15 * Mathf.Sign(n.transform.lossyScale.x) * Vector2.right, ForceMode2D.Impulse); GetComponent <Damageable>().dieAction += () => Destroy(gameObject); motion = GetComponent <MoveXCommand>(); attackCommand = GetComponent <ZombiAttack>(); stateMachine = GetComponent <UnitStateMachine>(); Patroler patroler = new Patroler(new StateInfo(transform, stateMachine), transform.position) { speed = BaseSpeed * 0.7f, time = 3f }; Follower follower = new Follower(new StateInfo(transform, stateMachine)) { maxSpeed = BaseSpeed }; MoveToPoint motionToPoint = new MoveToPoint(new StateInfo(transform, stateMachine), patroler.point, patroler) { speed = new Vector2(BaseSpeed * 0.8f, 0) }; //stateMachine.SetState(patroler); stateMachine.Initialize(follower); target = GameObject.FindGameObjectWithTag(targetTag).GetComponent <Rigidbody2D>(); follower.SetTarget(target); detectPlayer.Enter += () => stateMachine.SetState(follower); attackZone.Enter += () => stateMachine.SetState(new IdleState(new StateInfo(transform, stateMachine))); attackZone.Stay += () => attackCommand.Execute(); attackZone.Exit += () => stateMachine.SetState(follower); //lostZone.Exit += () => //{ // if (stateMachine.currentState == follower) // { // stateMachine.SetState(new WaitState(transform, stateMachine, 1, motionToPoint)); // } //}; }
// Start is called before the first frame update void Start() { stroke = GetComponent <MorticianStroke>(); charge = GetComponent <MorticianCharge>(); stateMachine = GetComponent <UnitStateMachine>(); Follower follower = new Follower(new StateInfo(transform, stateMachine)); player = GameObject.FindGameObjectWithTag("Player").transform; follower.SetTarget(player.GetComponent <Rigidbody2D>()); follower.maxSpeed = 4f; stateMachine.Initialize(follower); idle = new IdleState(new StateInfo(transform, stateMachine)); stroke.beginAttack += () => stateMachine.SetState(idle); stroke.endAttack += () => stateMachine.SetState(follower); }