// Start is called before the first frame update void Start() { var bounds = GameObject.Find("CameraBounds"); lowerbound = bounds.transform.position.y - bounds.transform.localScale.y / 2; player = GameObject.Find("Player"); tileSwitch = player.GetComponent <TileSwitch>(); playercontrol = player.GetComponent <PlayerController>(); }
void InitDynamicVolume() { tileSwitch = GameObject.Find("Player").GetComponent <TileSwitch>(); bounds = GameObject.Find("CameraBounds"); player = GameObject.Find("Player"); tileset1 = GameObject.Find("Tiles").GetComponent <Tilemap>(); tileset2 = GameObject.Find("Tiles2").GetComponent <Tilemap>(); tileSwitch = player.GetComponent <TileSwitch>(); vecMin = bounds.transform.position - bounds.transform.localScale / 2; vecMax = vecMin + bounds.transform.localScale; FindTilePositions(); StartCoroutine(SoundChecker()); }
// Fixed update is called just before calculating any physics private void FixedUpdate() { if (checkCrate) { checkPush(pushObject); } Vector2 velocity = rb2d.velocity; grounded = Grounded(); if (!grounded) { airbourne = true; } TileSwitch tileSwitch = GetComponent <TileSwitch>(); Tilemap tiles = tileSwitch.GetActiveTileset(); TileBase leftFootTile = tiles.GetTile(tiles.WorldToCell(leftFoot.transform.position)); TileBase rightFootTile = tiles.GetTile(tiles.WorldToCell(rightFoot.transform.position)); if ((leftFootTile != null && (leftFootTile.name == "jungleTilemap_9" || leftFootTile.name == "jungleTilemap_19" || leftFootTile.name == "jungleTilemap_8" || leftFootTile.name == "jungleTilemap_18")) || (rightFootTile != null && (rightFootTile.name == "jungleTilemap_9" || rightFootTile.name == "jungleTilemap_19" || rightFootTile.name == "jungleTilemap_8" || rightFootTile.name == "jungleTilemap_18"))) { if (!inWater) { velocity.x /= 2; velocity.y /= 3; AudioController.PlaySound("Splash"); timeInWater = Time.time; } inWater = true; if (Time.time - timeInWater > 1) { AudioController.PlaySound("PlayerHit"); health--; timeInWater++; } } else { inWater = false; } if (airbourne && grounded && previousVelocity != null && previousVelocity.y <= 0) { OnLanded(velocity.y >= 0 ? previousVelocity : velocity); } // apply enviromental forces (gravity / friction / hits) velocity.x += hitVelocity.x; if (velocity.x < 0) { velocity.x += FLOOR_FRICTION * Time.fixedDeltaTime * (inWater ? 2f : 1f); // stops friction changing player from sliding left to right, instead they should stop if (velocity.x > 0) { velocity.x = 0; } } else if (velocity.x > 0) { velocity.x -= FLOOR_FRICTION * Time.fixedDeltaTime * (inWater ? 2f : 1f); // stops friction changing player from sliding left to right, instead they should stop if (velocity.x < 0) { velocity.x = 0; } } velocity.y -= GRAVITY * Time.fixedDeltaTime * (inWater ? 0.1f : 1f); if (velocity.y < -TERMINAL_VELOCITY) { velocity.y = -TERMINAL_VELOCITY; } velocity.x += moveHorizontal * RUN_SPEED_ACCELERATION * Time.fixedDeltaTime * (inWater ? 0.5f : 1f); if (velocity.x > MAX_RUN_SPEED * (inWater ? 0.5f : 1f)) { velocity.x = MAX_RUN_SPEED * (inWater ? 0.5f : 1f); } else if (velocity.x < -(MAX_RUN_SPEED * (inWater ? 0.5f : 1f))) { velocity.x = -(MAX_RUN_SPEED * (inWater ? 0.5f : 1f)); } if (jump) { velocity.y = JUMP_ACCELERATION; AudioController.PlaySound("Jump"); } rb2d.velocity = velocity; previousVelocity = velocity; hitVelocity.x = 0; jump = false; falling = velocity.y < 0 && !grounded; if (health <= 0) { Die(); } }
// Start is called before the first frame update void Start() { StartCoroutine(Shoot(3)); tileSwitch = GameObject.Find("Player").GetComponent <TileSwitch>(); }