Player.cs 539 B

12345678910111213141516171819
  1. using UnityEngine;
  2. namespace Mirror.Examples.Pong
  3. {
  4. public class Player : NetworkBehaviour
  5. {
  6. public float speed = 30;
  7. public Rigidbody2D rigidbody2d;
  8. // need to use FixedUpdate for rigidbody
  9. void FixedUpdate()
  10. {
  11. // only let the local player control the racket.
  12. // don't control other player's rackets
  13. if (isLocalPlayer)
  14. rigidbody2d.velocity = new Vector2(0, Input.GetAxisRaw("Vertical")) * speed * Time.fixedDeltaTime;
  15. }
  16. }
  17. }