// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (m_enemyNearestPosition == null) { m_enemyNearestPosition = FindObjectOfType <BaseEnemy>().transform; } if (Vector2.Distance(animator.transform.position, m_enemyNearestPosition.transform.position) > m_chasingDistance) { animator.transform.position = Vector2.MoveTowards(animator.transform.position, m_enemyNearestPosition.transform.position , m_speed * Time.deltaTime); } if (Vector2.Distance(animator.transform.position, m_enemyNearestPosition.transform.position) < m_retreatDistance) { animator.transform.position = Vector2.MoveTowards(animator.transform.position, m_enemyNearestPosition.transform.position , -m_speed * Time.deltaTime); } if (Vector2.Distance(animator.transform.position, m_enemyNearestPosition.transform.position) < m_chasingDistance && Vector2.Distance(animator.transform.position, m_enemyNearestPosition.transform.position) > m_retreatDistance) { animator.transform.position = animator.transform.position; } else if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) > m_chasingDistance * m_aggroRange) { animator.SetBool("isPatrolling", true); animator.SetBool("isAttacking", false); m_sceneManager.changeStateOfCombat(false); } }
public void die() { m_manager.changeStateOfCombat(false); healthBarImage.fillAmount = 0; OuterHealthBar.SetActive(false); TrashMan.despawn(gameObject); }
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //This move the enemy to the points with a Sin Wave animator.transform.localPosition = Vector2.MoveTowards(animator.transform.localPosition, m_points * Mathf.Sin(Time.time * 0.2f) * 1f, m_speed * Time.deltaTime); //if it is getting closer to the point if (Vector2.Distance(animator.transform.localPosition, m_points) < 0.2f) { //if the waitTime < 0; Call a new point; Else; wait; if (waitTime <= 0) { m_points = Random.insideUnitCircle * 10; waitTime = m_startWaitTime; } else { waitTime -= Time.deltaTime; } } //if the distance between the player and the enemy is lesser than m_distanceToPlayer if (Vector2.Distance(animator.transform.position, m_playerPosition.position) < m_distanceToPlayer) { //set the animator parameters animator.SetBool("isAttacking", true); animator.SetBool("isPatrolling", false); //set the state of combat m_sceneManager.changeStateOfCombat(true); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.GetComponent <BaseShip>() != null) { manager.changeStateOfCombat(true); Debug.Log("State of combat: " + manager.stateOfCombat); TrashMan.despawn(gameObject); } }
void Update() { m_enemiesInChildren = transform.childCount; if (m_enemiesInChildren <= 0) { m_sceneManager.changeStateOfCombat(false); TrashMan.despawn(gameObject); } }
public void die() { m_manager.changeStateOfCombat(false); canvasRestart.SetActive(true); TrashMan.despawn(gameObject); }
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //For the lancer to work, every instance of it must be named in capital letters "LANCER" #region Lancer if (animator.name == "LANCER") { if (m_accel >= 4) { speed += m_accel * 3; m_accel = 1; } //gets the boolean "isAttached" from the lancer class. The attachment will always be true if the lancer contacted the player if (animator.GetComponent <LANCER>().isAttached == true) { //Change the enemy parent, being it now the playerShip animator.transform.parent = m_playerPosition.transform; animator.rootPosition = new Vector3(0, 0, 0); //disable own collider for preventing bugs purpose animator.GetComponent <Collider2D>().enabled = false; m_accel = 0; } //IF the lancer isn't attached to player... if (animator.GetComponent <LANCER>().isAttached == false) { /*I don't know how this works, but basically if you put the .right of your object to be the subtraction of target position * minus its own position, the object will rotate for that direction*/ Vector3 _rot = animator.transform.right = m_playerPosition.position - animator.transform.position; animator.rootPosition = _rot; m_accel += 2f * Time.deltaTime; //if the distance between the enemy and the player is greater than the m_chasingDistance, move towards the player if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) > m_chasingDistance) { animator.transform.position = Vector2.MoveTowards(animator.transform.position, m_playerPosition.transform.position , speed * Time.deltaTime); } //if the distance between the enemy and the player is lesser than the m_retreatDistance, move towards the player if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) < m_retreatDistance) { animator.transform.position = Vector2.MoveTowards(animator.transform.position, m_playerPosition.transform.position , -speed * Time.deltaTime); } //if it is between the two above, do nothing; if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) < m_chasingDistance && Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) > m_retreatDistance) { animator.transform.position = animator.transform.position; } //This is the controller that sets the enemy back to patrolling position the distance between player and enemy is greater than chasing distance time aggroRange else if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) > m_chasingDistance * m_aggroRange) { //setting the animator parameters animator.SetBool("isPatrolling", true); animator.SetBool("isAttacking", false); //setting the stateofCombat to the scene manager m_sceneManager.changeStateOfCombat(false); } } } #endregion #region Chase/Strafe Code if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) > m_chasingDistance) { animator.transform.position = Vector2.MoveTowards(animator.transform.position, m_playerPosition.transform.position , speed * Time.deltaTime); } //if the distance between the enemy and the player is lesser than the m_retreatDistance, move towards the player if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) < m_retreatDistance) { animator.transform.position = Vector2.MoveTowards(animator.transform.position, m_playerPosition.transform.position , -speed * Time.deltaTime); } //if it is between the two above, do nothing; if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) < m_chasingDistance && Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) > m_retreatDistance) { animator.transform.position = animator.transform.position; } //This is the controller that sets the enemy back to patrolling position the distance between player and enemy is greater than chasing distance time aggroRange else if (Vector2.Distance(animator.transform.position, m_playerPosition.transform.position) > m_chasingDistance * m_aggroRange) { //setting the animator parameters animator.SetBool("isPatrolling", true); animator.SetBool("isAttacking", false); //setting the stateofCombat to the scene manager m_sceneManager.changeStateOfCombat(false); } #endregion if (m_playerPosition == null) { m_playerPosition = GameObject.FindGameObjectWithTag("Player").transform; } }