private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "PlayerBullet") { Destroy(collision.gameObject); health--; bodySR.material = matWhite; if (player.transform.position.x > transform.position.x) { bodySR.flipX = false; } else { bodySR.flipX = true; } if (health <= 0) { gameObject.GetComponent <BoxCollider2D>().enabled = false; currentState = TreeEnemyStates.Die; if (isAlive == true) { SpookyWoodBoss.instance.enemyCounter--; isAlive = false; } } else { counter = TimeToGetHit; currentState = TreeEnemyStates.Hit; Invoke("ResetMaterial", 0.1f); //jak dlugo ma byc bialy } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "PlayerBullet") { Destroy(collision.gameObject); bodySR.material = matWhite; if (player.transform.position.x > transform.position.x) { bodySR.flipX = false; } else { bodySR.flipX = true; } if (genEnemy.health <= 0) { gameObject.GetComponent <BoxCollider2D>().enabled = false; currentState = TreeEnemyStates.Die; } else { counter = TimeToGetHit; currentState = TreeEnemyStates.Hit; Invoke("ResetMaterial", 0.1f); //jak dlugo ma byc bialy } } if (collision.tag == "Player") { if (SAYController.instance.isInvincible == false) { CameraShaker.ShakeStrong(.20f, .35f); SAYPlayerHealthController.instance.DamagePlayer(); Destroy(gameObject); } } }
void Update() { if (SpookyWoodBoss.instance.isDead) { Instantiate(expolsionRef, transform.position, Quaternion.identity); Destroy(gameObject); } switch (currentState) { case TreeEnemyStates.Walk: ChangeAnimationState("WoodBossMinion_Walk"); float distance = Vector2.Distance(transform.position, player.position); transform.position = Vector2.MoveTowards(transform.position, player.transform.position, speed * Time.deltaTime); // If we are close enough we will shoot if (distance < shootDistance) { if (lastBullet > 0) { lastBullet -= Time.deltaTime; } else { numBulletsShoot++; if (numBulletsShoot < howManyBulletsToSpawn) { // Max "howManyBulletsToSpawn" bullets before reloading lastBullet = TimeBetweenBullets; Instantiate(projectile, transform.position, Quaternion.identity); // The bullet should move in some way, there is no code here to move the bullet } else { // Reloading lastBullet = TimeToReload; // 2 seconds reload numBulletsShoot = 0; } } } break; case TreeEnemyStates.Hit: ChangeAnimationState("WoodBossMinion_Hit"); if (counter > 0) { counter -= Time.deltaTime; Vector3 moveDirection = transform.position - player.transform.position; moveDirection.Normalize(); rb.velocity = moveDirection * speedWhenHit; } else { rb.velocity = Vector2.zero; counter = TimeToGetHit; bodySR.flipX = false; currentState = TreeEnemyStates.Walk; } break; case TreeEnemyStates.Die: //CameraShaker.Shake(0.10f, 0.15f); Invoke("ResetMaterial", 0.1f); //jak dlugo ma byc bialy ChangeAnimationState("WoodBossMinion_Hit"); Vector3 movingWay = transform.position - player.transform.position; movingWay.Normalize(); rb.velocity = movingWay * speedWhenDie; Invoke("KillSelf", howLongAwayAfterDestroyed); CameraShaker.ShakeStrong(.20f, .25f); currentState = TreeEnemyStates.PostMortem; break; case TreeEnemyStates.PostMortem: break; } // Calculate the distance }
void Update() { if (!theRoom.roomActive) { return; } switch (currentState) { case TreeEnemyStates.Idle: if (Vector2.Distance(transform.position, player.transform.position) < distanceToTrigger) { currentState = TreeEnemyStates.Walk; Debug.Log("idle"); } break; case TreeEnemyStates.Walk: ChangeAnimationState("TreeMonster_Move"); Debug.Log("walk"); float distance = Vector2.Distance(transform.position, player.position); // If we are too close or too far away we will stop. If not we will go towards the player if (distance < reatreatDistance) { Debug.Log("Run"); transform.position = Vector2.MoveTowards(transform.position, player.transform.position, -speed * Time.deltaTime); } else if (distance > minDistance && distance < maxDistance) { Debug.Log("chase"); transform.position = Vector2.MoveTowards(transform.position, player.transform.position, speed * Time.deltaTime); } else { transform.position = Vector2.MoveTowards(transform.position, transform.position, speed * Time.deltaTime); } // If we are close enough we will shoot if (distance < shootDistance) { if (lastBullet > 0) { lastBullet -= Time.deltaTime; } else { numBulletsShoot++; if (numBulletsShoot < howManyBulletsToSpawn) { // Max "howManyBulletsToSpawn" bullets before reloading lastBullet = TimeBetweenBullets; Instantiate(projectile, transform.position, Quaternion.identity); // The bullet should move in some way, there is no code here to move the bullet } else { // Reloading lastBullet = TimeToReload; // 2 seconds reload numBulletsShoot = 0; } } } break; case TreeEnemyStates.Hit: ChangeAnimationState("Tree_Monster_Hit"); if (counter > 0) { counter -= Time.deltaTime; Vector3 moveDirection = transform.position - player.transform.position; moveDirection.Normalize(); rb.velocity = moveDirection * speedWhenHit; } else { rb.velocity = Vector2.zero; counter = TimeToGetHit; bodySR.flipX = false; currentState = TreeEnemyStates.Walk; } break; case TreeEnemyStates.Die: //CameraShaker.Shake(0.10f, 0.15f); Invoke("ResetMaterial", 0.1f); //jak dlugo ma byc bialy ChangeAnimationState("Tree_Monster_Hit"); Vector3 movingWay = transform.position - player.transform.position; movingWay.Normalize(); rb.velocity = movingWay * speedWhenDie; Invoke("KillSelf", howLongAwayAfterDestroyed); CameraShaker.ShakeStrong(.20f, .25f); currentState = TreeEnemyStates.PostMortem; break; case TreeEnemyStates.PostMortem: break; } // Calculate the distance }
void Update() { if (!theRoom.roomActive) { return; } switch (currentState) { case TreeEnemyStates.Idle: if (Vector2.Distance(transform.position, player.transform.position) < distanceToTrigger) { currentState = TreeEnemyStates.Walk; Debug.Log("idle"); } break; case TreeEnemyStates.Walk: ChangeAnimationState("RedBlueMonster_Move"); float distance = Vector2.Distance(transform.position, player.position); if (counterToStop > 0) { counterToStop -= Time.deltaTime; transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime); // If we are close enough we will shoot if (distance < shootDistance) { if (lastBullet > 0) { lastBullet -= Time.deltaTime; } else { lastBullet = TimeBetweenBullets; Instantiate(projectile, transform.position, Quaternion.identity); // The bullet should move in some way, there is no code here to move the bullet } } } else { if (counTheBreak > 0) { counTheBreak -= Time.deltaTime; } else { counTheBreak = CountTheBreakTime; counterToStop = StopTime; } } break; case TreeEnemyStates.Hit: ChangeAnimationState("RedBlueMonster_Hit"); if (counter > 0) { counter -= Time.deltaTime; Vector3 moveDirection = transform.position - player.transform.position; moveDirection.Normalize(); rb.velocity = moveDirection * speedWhenHit; } else { rb.velocity = Vector2.zero; counter = TimeToGetHit; bodySR.flipX = false; currentState = TreeEnemyStates.Walk; } break; case TreeEnemyStates.Die: //CameraShaker.Shake(0.10f, 0.15f); Invoke("ResetMaterial", 0.1f); //jak dlugo ma byc bialy ChangeAnimationState("RedBlueMonster_Hit"); Vector3 movingWay = transform.position - player.transform.position; movingWay.Normalize(); rb.velocity = movingWay * speedWhenDie; Invoke("KillSelf", howLongAwayAfterDestroyed); CameraShaker.ShakeStrong(.20f, .25f); currentState = TreeEnemyStates.PostMortem; break; case TreeEnemyStates.PostMortem: break; } // Calculate the distance }