Ball.cs 716 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using UnityEngine;
  5. public class Ball : MonoBehaviour
  6. {
  7. public bool IsInUse { get; private set; }
  8. public float speed = 5f;
  9. public void Recenter()
  10. {
  11. var component = GetComponent<Rigidbody>();
  12. component.velocity = Vector3.zero;
  13. component.transform.position = Vector3.zero;
  14. IsInUse = false;
  15. }
  16. public void Kickoff()
  17. {
  18. float sx = Random.Range(0, 2) == 0 ? -1 : 1;
  19. float sz = Random.Range(0, 2) == 0 ? -1 : 1;
  20. GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, 0f, speed * sz);
  21. IsInUse = true;
  22. }
  23. }