Move away from FixedUpdate entirely
This commit is contained in:
5 files changed
+93
-116
No files matched your search
@@ -201,12 +201,12 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
bird.transform.position += new UnityEngine.Vector3(-(2.4f * (speedModifier * canvasRect.lossyScale.x)), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
bird.transform.position += new UnityEngine.Vector3(2.4f * (speedModifier * canvasRect.lossyScale.x), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
@@ -253,31 +253,6 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
birdRect.anchoredPosition = pos;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf) {
|
||||
MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||
} else if (slownessLeft > 0f) {
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||
} else if (speedyLeft > 0f) {
|
||||
speedyLeft -= Time.deltaTime;
|
||||
boostText.text = "Speed expires in " + string.Format("{0:0.0}", speedyLeft) + "s";
|
||||
} else if (antiLeft > 0f) {
|
||||
antiLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry repellent expires in " + string.Format("{0:0.0}", antiLeft) + "s";
|
||||
} else if (goldenLeft > 0f) {
|
||||
goldenLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry magnet expires in " + string.Format("{0:0.0}", goldenLeft) + "s";
|
||||
} else {
|
||||
boostText.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpawnBerries() {
|
||||
if (Time.time < nextSpawnTime) {
|
||||
return;
|
||||
@@ -332,7 +307,27 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
|
||||
if (!pausePanel.activeSelf)
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf) {
|
||||
MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||
} else if (slownessLeft > 0f) {
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||
} else if (speedyLeft > 0f) {
|
||||
speedyLeft -= Time.deltaTime;
|
||||
boostText.text = "Speed expires in " + string.Format("{0:0.0}", speedyLeft) + "s";
|
||||
} else if (antiLeft > 0f) {
|
||||
antiLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry repellent expires in " + string.Format("{0:0.0}", antiLeft) + "s";
|
||||
} else if (goldenLeft > 0f) {
|
||||
goldenLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry magnet expires in " + string.Format("{0:0.0}", goldenLeft) + "s";
|
||||
} else {
|
||||
boostText.text = "";
|
||||
}
|
||||
foreach (GameObject berry in berries.ToList()) {
|
||||
if (berry == null) {
|
||||
berries.Remove(berry);
|
||||
@@ -371,6 +366,7 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
}
|
||||
if (berry != null) berry.GetComponent<Rigidbody2D>().linearVelocity = noGravityBerries.Contains(berry.GetInstanceID()) ? UnityEngine.Vector2.zero : new UnityEngine.Vector2(0f, speedyLeft == 0.0f ? (-300f * canvasRect.lossyScale.y) : (-550f * canvasRect.lossyScale.y));
|
||||
}
|
||||
}
|
||||
if ((Application.platform == RuntimePlatform.Android && Keyboard.current.escapeKey.wasPressedThisFrame) || !Application.isMobilePlatform && (Keyboard.current.escapeKey.wasPressedThisFrame || (Gamepad.current != null && (Gamepad.current.startButton.wasPressedThisFrame || Gamepad.current.buttonEast.wasPressedThisFrame)))) TogglePause();
|
||||
}
|
||||
|
||||
|
||||
@@ -155,12 +155,12 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
bird.transform.position += new UnityEngine.Vector3(-(2.4f * (speedModifier * canvasRect.lossyScale.x)), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
bird.transform.position += new UnityEngine.Vector3(2.4f * (speedModifier * canvasRect.lossyScale.x), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
@@ -336,12 +336,12 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
bird.transform.position += new UnityEngine.Vector3(-(2.4f * (speedModifier * canvasRect.lossyScale.x)), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
bird.transform.position += new UnityEngine.Vector3(2.4f * (speedModifier * canvasRect.lossyScale.x), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
@@ -388,32 +388,6 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
birdRect.anchoredPosition = pos;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf) {
|
||||
if (useAI) MoveBirdAI();
|
||||
else MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||
} else if (slownessLeft > 0f) {
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||
} else if (speedyLeft > 0f) {
|
||||
speedyLeft -= Time.deltaTime;
|
||||
boostText.text = "Speed expires in " + string.Format("{0:0.0}", speedyLeft) + "s";
|
||||
} else if (antiLeft > 0f) {
|
||||
antiLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry repellent expires in " + string.Format("{0:0.0}", antiLeft) + "s";
|
||||
} else if (goldenLeft > 0f) {
|
||||
goldenLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry magnet expires in " + string.Format("{0:0.0}", goldenLeft) + "s";
|
||||
} else {
|
||||
boostText.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpawnBerries() {
|
||||
if (Time.time < nextSpawnTime) {
|
||||
return;
|
||||
@@ -498,7 +472,28 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
|
||||
if (!pausePanel.activeSelf)
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf) {
|
||||
if (useAI) MoveBirdAI();
|
||||
else MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||
} else if (slownessLeft > 0f) {
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||
} else if (speedyLeft > 0f) {
|
||||
speedyLeft -= Time.deltaTime;
|
||||
boostText.text = "Speed expires in " + string.Format("{0:0.0}", speedyLeft) + "s";
|
||||
} else if (antiLeft > 0f) {
|
||||
antiLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry repellent expires in " + string.Format("{0:0.0}", antiLeft) + "s";
|
||||
} else if (goldenLeft > 0f) {
|
||||
goldenLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry magnet expires in " + string.Format("{0:0.0}", goldenLeft) + "s";
|
||||
} else {
|
||||
boostText.text = "";
|
||||
}
|
||||
foreach (GameObject berry in berries.ToList()) {
|
||||
if (berry == null) {
|
||||
berries.Remove(berry);
|
||||
@@ -540,6 +535,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
if (berry != null) berry.GetComponent<Rigidbody2D>().linearVelocity = noGravityBerries.Contains(berry.GetInstanceID()) ? UnityEngine.Vector2.zero : new UnityEngine.Vector2(0f, speedyLeft == 0.0f ? (-300f * canvasRect.lossyScale.y) : (-550f * canvasRect.lossyScale.y));
|
||||
}
|
||||
}
|
||||
if ((Application.platform == RuntimePlatform.Android && Keyboard.current.escapeKey.wasPressedThisFrame) || !Application.isMobilePlatform && (Keyboard.current.escapeKey.wasPressedThisFrame || (Gamepad.current != null && (Gamepad.current.startButton.wasPressedThisFrame || Gamepad.current.buttonEast.wasPressedThisFrame)))) TogglePause();
|
||||
}
|
||||
|
||||
|
||||
@@ -141,12 +141,12 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
bird.transform.position += new UnityEngine.Vector3(-(2.4f * (speedModifier * canvasRect.lossyScale.x)), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
bird.transform.position += new UnityEngine.Vector3(2.4f * (speedModifier * canvasRect.lossyScale.x), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
@@ -196,31 +196,6 @@ public class GamePlayer : MonoBehaviour {
|
||||
birdRect.anchoredPosition = pos;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf) {
|
||||
MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||
} else if (slownessLeft > 0f) {
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||
} else if (speedyLeft > 0f) {
|
||||
speedyLeft -= Time.deltaTime;
|
||||
boostText.text = "Speed expires in " + string.Format("{0:0.0}", speedyLeft) + "s";
|
||||
} else if (antiLeft > 0f) {
|
||||
antiLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry repellent expires in " + string.Format("{0:0.0}", antiLeft) + "s";
|
||||
} else if (goldenLeft > 0f) {
|
||||
goldenLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry magnet expires in " + string.Format("{0:0.0}", goldenLeft) + "s";
|
||||
} else {
|
||||
boostText.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpawnBerries() {
|
||||
if (Time.time < nextSpawnTime) {
|
||||
return;
|
||||
@@ -278,7 +253,27 @@ public class GamePlayer : MonoBehaviour {
|
||||
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
|
||||
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
|
||||
if (!pausePanel.activeSelf)
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf) {
|
||||
MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||
} else if (slownessLeft > 0f) {
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||
} else if (speedyLeft > 0f) {
|
||||
speedyLeft -= Time.deltaTime;
|
||||
boostText.text = "Speed expires in " + string.Format("{0:0.0}", speedyLeft) + "s";
|
||||
} else if (antiLeft > 0f) {
|
||||
antiLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry repellent expires in " + string.Format("{0:0.0}", antiLeft) + "s";
|
||||
} else if (goldenLeft > 0f) {
|
||||
goldenLeft -= Time.deltaTime;
|
||||
boostText.text = "Berry magnet expires in " + string.Format("{0:0.0}", goldenLeft) + "s";
|
||||
} else {
|
||||
boostText.text = "";
|
||||
}
|
||||
foreach (GameObject berry in berries.ToList()) {
|
||||
if (berry == null) {
|
||||
berries.Remove(berry);
|
||||
@@ -320,6 +315,7 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
if (berry != null) berry.GetComponent<Rigidbody2D>().linearVelocity = noGravityBerries.Contains(berry.GetInstanceID()) ? UnityEngine.Vector2.zero : new UnityEngine.Vector2(0f, speedyLeft == 0.0f ? (-300f * canvasRect.lossyScale.y) : (-550f * canvasRect.lossyScale.y));
|
||||
}
|
||||
}
|
||||
if ((Application.platform == RuntimePlatform.Android && Keyboard.current.escapeKey.wasPressedThisFrame) || !Application.isMobilePlatform && (Keyboard.current.escapeKey.wasPressedThisFrame || (Gamepad.current != null && (Gamepad.current.startButton.wasPressedThisFrame || Gamepad.current.buttonEast.wasPressedThisFrame)))) TogglePause();
|
||||
}
|
||||
|
||||
|
||||
@@ -215,12 +215,12 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
bird.transform.position += new UnityEngine.Vector3(-(2.4f * (speedModifier * canvasRect.lossyScale.x)), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
bird.transform.position += new UnityEngine.Vector3(2.4f * (speedModifier * canvasRect.lossyScale.x), 0f, 0f);
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
@@ -260,27 +260,6 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
birdRect.anchoredPosition = pos;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
if (disconnecting) return;
|
||||
if (WebsocketHandler.Instance != null) {
|
||||
var ping = WebsocketHandler.Instance.GetPing();
|
||||
if (ping == -1f) pingText.text = "";
|
||||
else pingText.text = $"Ping: {Math.Floor(ping)}ms";
|
||||
}
|
||||
if (!pausePanel.activeSelf) {
|
||||
MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||
} else if (slownessLeft > 0f) {
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||
} else {
|
||||
boostText.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (disconnecting) return;
|
||||
UnityEngine.Vector2 currentScreenSize = new(Screen.width, Screen.height);
|
||||
@@ -290,7 +269,22 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
return;
|
||||
}
|
||||
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
|
||||
if (WebsocketHandler.Instance != null) {
|
||||
var ping = WebsocketHandler.Instance.GetPing();
|
||||
if (ping == -1f) pingText.text = "";
|
||||
else pingText.text = $"Ping: {Math.Floor(ping)}ms";
|
||||
}
|
||||
ProcessSpawns();
|
||||
MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||
} else if (slownessLeft > 0f) {
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||
} else {
|
||||
boostText.text = "";
|
||||
}
|
||||
|
||||
foreach (GameObject berry in berries.Values.ToList()) {
|
||||
if (berry == null) {
|
||||
|
||||
Reference in new issue
Block a user