//void Awake() //{ // eman = GameObject.FindWithTag("Manager").GetComponent<EnemyManager>(); //} private State_Attack() { if (_Instance != null) { return; } _Instance = this; }
protected virtual void Awake() { myRigidbody = GetComponent <Rigidbody2D>(); //Animation myAnimator = GetComponent <Animator>(); //State attackState = GetComponent <State_Attack>(); deathState = GetComponent <State_Death>(); dodgeState = GetComponent <State_Dodge>(); guardState = GetComponent <State_Guard>(); hitState = GetComponent <State_Hit>(); idleState = GetComponent <State_Idle>(); moveState = GetComponent <State_Move>(); battle_idleState = GetComponent <State_Battle_Idle>(); skillUseState = GetComponent <State_SkillUse>(); targetSearchState = GetComponent <State_TargetSearch>(); }
void OnTriggerEnter(Collider col) { // Check if player is in vision range if (col.attachedRigidbody && col.attachedRigidbody.gameObject.name.Equals("Player")) { // Determine which state we should change to if (stateMachine.GetStateName().Equals("Patrol") || stateMachine.GetStateName().Equals("Return")) { visionRange.enabled = false; attackCollider.enabled = true; // Change to chase state State_Chase state = new State_Chase(this); state.SetAnimator(anim); state.SetSpeed(moveSpeed); state.SetNavAgent(navAgent); state.SetChaseTarget(col.attachedRigidbody.gameObject); stateMachine.SetState(state); attackCollider.radius = attackRange; return; } else if (stateMachine.GetStateName().Equals("Chase")) { playerInRange = true; // Change to attack state State_Attack state = new State_Attack(this); state.SetAnimator(anim); state.SetTarget(col.attachedRigidbody.gameObject); state.SetAttackDelay(attackDelay); state.SetAttackCooldown(attackCooldown); state.SetProjectile(projectile, attackDamage, 0, attackRange); stateMachine.SetState(state); // Keep the attack more persistent attackCollider.radius = attackRange * 1.25f; } } }