// Player inputs should always be in Update() since FixedUpdate() doesn't poll fast enough void Update() { // To prevent actions while paused if (Time.timeScale > 0.1 && (photonView == null || photonView.IsMine)) { if (player.GetButton("Fire")) { baseBulletSpawner.Spawn(); } if (player.GetButtonDown("Bomb") && bombsLeft > 0) { bombSpawner.Spawn(bombsLeft); bombsLeft--; Debug.Log(bombsLeft); } // Metered moves if (player.GetButtonLongPressUp("Super1") && vars.Energy >= ultraCost) { GatesOfBabylon gateController = gatesOfBabylon.GetComponent <GatesOfBabylon>(); gateController.ActivateGates(); vars.Energy -= ultraCost; } else if (player.GetButtonUp("Super1") && vars.Energy >= superOneCost) { baseBulletSpawner.SpawnSuperBullet(); vars.Energy -= superOneCost; Debug.Log("short hold"); } } }
private void LerpMove() { // Move to end position if (Math.Abs(transform.position.x - end.position.x) > 0.1) { float distCovered = (Time.time - startTime) * speed; float fractionOfJourney = distCovered / journeyLength; Vector3 lerpPosition = Vector3.Lerp(start.position, end.position, fractionOfJourney); Vector3 newGatePosition = new Vector2(lerpPosition.x, transform.position.y); transform.position = newGatePosition; } // At end position if (Math.Abs(transform.position.x - end.position.x) <= 0.1) { if (bulletsFired < bulletsToFire && Time.time > nextFireTime) { nextFireTime = Time.time + fireRate; baseBulletSpawner.Spawn(); bulletsFired++; middleTime = Time.time; } } // Move to start position if (bulletsFired == bulletsToFire) { float distCovered = (Time.time - middleTime) * speed; float fractionOfJourney = distCovered / journeyLength; Vector3 lerpPosition = Vector3.Lerp(end.position, start.position, fractionOfJourney); Vector2 newGatePosition = new Vector2(lerpPosition.x, transform.position.y); transform.position = newGatePosition; // Reset if (Math.Abs(transform.position.x - start.position.x) < 0.1) { bulletsFired = 0; readyToFire = false; } } }