Ball.cs 525 B

1234567891011121314151617181920212223
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Ball : MonoBehaviour
  5. {
  6. public float speed = 5f;
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. float sx = Random.Range(0, 2) == 0 ? -1 : 1;
  11. float sy = Random.Range(0, 2) == 0 ? -1 : 1;
  12. GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, speed * sy, 0f);
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. }
  18. }