private ShootPlayer shootPlayer; // call class ShootPlayer // Start is called before the first frame update void Start() { InvokeRepeating("UpdateTarget", 0f, 0.5f); enermyMove = GetComponent <EnermyMove>(); enermyMoveRandomly = GetComponent <EnermyMoveRandomly>(); shootPlayer = GetComponent <ShootPlayer>(); }
private void Awake() { //pick reference Player = FindObjectOfType <PlayerController>(); MyWeapon = GetComponent <RangedWeapon>(); //SetupEnemyType enemyType = EnemyType.typeB; //state machine setup _stateMachine = new StateMachine(); var Sight = new SightPlayer(this); var Shoot = new ShootPlayer(this); var ZigZag = new ZigZagMovement(this); //add transition between state AddTransition(Sight, ZigZag, SpottedPlayer()); AddTransition(Shoot, ZigZag, HasShooted()); AddTransition(ZigZag, Shoot, ReachedNextPoint()); //set conidtions Func <bool> SpottedPlayer() => () => EnableShooting(); Func <bool> HasShooted() => () => ShootingTimer >= ShootingDuration; Func <bool> ReachedNextPoint() => () => agent.remainingDistance <= agent.stoppingDistance; _stateMachine.SetState(Sight); }
// Use this for initialization void Start() { if (chasing) { chase_player = GetComponentInParent <ChasePlayer>(); } else { shoot_player = GetComponentInParent <ShootPlayer>(); } }
protected override void MakeFSM() { // Follow behaviour FollowPlayer follow = new FollowPlayer(attackRange, playerAttackLayer, this); follow.AddTransition(Transition.InPlayerAttackRange, StateID.AttackPlayer); follow.AddTransition(Transition.ReachedDestination, StateID.Idle); // Attack behaviour ShootPlayer shoot = new ShootPlayer(attackRange, playerAttackLayer, attackInterval, this); shoot.AddTransition(Transition.LostPlayerAttackRange, StateID.FollowPlayer); shoot.AddTransition(Transition.ReachedDestination, StateID.Idle); // Idle behaviour IdleEnemy idle = new IdleEnemy(); idle.AddTransition(Transition.SawPlayer, StateID.FollowPlayer); fsm = new FSMSystem(); fsm.AddState(follow); fsm.AddState(shoot); fsm.AddState(idle); }