private void Activate() { switch (type.ToString()) { case "SlowMotion": Time.timeScale = 0.5f; break; case "BiggerPlatform": Fireman.GetInstance().ChangeScale(1.5f); break; case "Mattress": InstancedMattress = Instantiate(Mattress); break; } }
private void OnTriggerEnter2D(Collider2D collision) { if (state == State.Playing) { if (collision.tag == "Player") { if (type != Type.Obstacle) { Level.GetInstance().ApplyPowerUp(type.ToString()); Destroy(gameObject); } else { Fireman.GetInstance().HurtFireman(); Destroy(gameObject); } } else if (collision.tag == "Ground") { Destroy(gameObject); } } }
private void Jump(bool hitFireman) { if (hitFireman) { float positionDiff = transform.position.x - Fireman.GetInstance().GetPosition().x; float xSize = transform.localScale.x * 0.8f; if (positionDiff <= xSize && positionDiff >= -xSize) { rb.velocity = new Vector2(Mathf.Abs(rb.velocity.x), -rb.velocity.y); } else if (positionDiff > xSize) { rb.velocity = new Vector2(Mathf.Abs(rb.velocity.x) * -0.9f, -rb.velocity.y); } else { rb.velocity = new Vector2(Mathf.Abs(rb.velocity.x) * 1.1f, -rb.velocity.y); } } else { rb.velocity = new Vector2(Mathf.Abs(rb.velocity.x), -rb.velocity.y); } }
//Checks if the timer is finished and if so cancels it's effect and returns true public bool UpdateTimer(float deltaTime) { timer -= deltaTime; if (timer < 0) { switch (type.ToString()) { case "SlowMotion": Time.timeScale = 1f; return(true); case "BiggerPlatform": Fireman.GetInstance().ChangeScale(1f); return(true); case "Mattress": InstancedMattress.gameObject.GetComponent <Animator>().SetTrigger("Popped"); Destroy(InstancedMattress.gameObject, 2f); return(true); } } return(false); }