Ball.cs 889 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // Start is called before the first frame update
  10. void Start()
  11. {
  12. }
  13. public void Recenter()
  14. {
  15. var component = GetComponent<Rigidbody>();
  16. component.velocity = Vector3.zero;
  17. component.transform.position = Vector3.zero;
  18. IsInUse = false;
  19. }
  20. public void Kickoff()
  21. {
  22. float sx = Random.Range(0, 2) == 0 ? -1 : 1;
  23. float sz = Random.Range(0, 2) == 0 ? -1 : 1;
  24. GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, 0f, speed * sz);
  25. IsInUse = true;
  26. }
  27. // Update is called once per frame
  28. void Update()
  29. {
  30. }
  31. }