AtariPongRacket.cs 703 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. using Mirror;
  3. namespace Ignorance.Examples.PongChamp
  4. {
  5. public class AtariPongRacket : NetworkBehaviour
  6. {
  7. public float speed = 1500;
  8. private Rigidbody2D rigidbody2d;
  9. private void Awake()
  10. {
  11. rigidbody2d = GetComponent<Rigidbody2D>();
  12. }
  13. // need to use FixedUpdate for rigidbody
  14. void FixedUpdate()
  15. {
  16. // only let the local player control the racket.
  17. // don't control other player's rackets
  18. if (isLocalPlayer)
  19. rigidbody2d.velocity = new Vector2(0, Input.GetAxisRaw("Vertical")) * speed * Time.fixedDeltaTime;
  20. }
  21. }
  22. }