GiveBoostIfMovingOnXorYAxis









How do I use Give Boost If Moving On Xor Y Axis
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: BallScript.cs Copy
18     void Update()
19     {
20         if (GameManager.CurrentGameState == GameManager.GameState.Playing)
21             GiveBoostIfMovingOnXorYAxis();
22     }
File name: BallScript.cs Copy
24     private void GiveBoostIfMovingOnXorYAxis()
25     {
26         if (Mathf.Abs(GetComponent().velocity.x - 0.2f) <= 0.2f)
27         {
28             //left or right?
29             bool right = Random.Range(-1.0f, 1.0f) >= 0;
30             GetComponent().AddForce(new Vector2(right ? 5.0f : -5.0f, 0), ForceMode2D.Impulse);
31         }
32
33         if (Mathf.Abs(GetComponent().velocity.y - 0.2f) <= 0.2f)
34         {
35             //up or down?
36             bool down = Random.Range(-1.0f, 1.0f) >= 0;
37             GetComponent().AddForce(new Vector2(0, down ? 5.0f : -5.0f), ForceMode2D.Impulse);
38         }
39     }

GiveBoostIfMovingOnXorYAxis 136 lượt xem

Gõ tìm kiếm nhanh...