using System.Collections; using UnityAtoms.BaseAtoms; using UnityEngine; namespace MAVRIC.GEEKCup { public class GameLogic : MonoBehaviour { [SerializeField] private GameObject ball; [SerializeField] private IntVariable scoreVariable; [SerializeField] private GameObject OffScreenSpawnPoint; private GameObject spawnPoint; private Transform ballStartTransform; public void CheckForSpawnPoint() { ballStartTransform = OffScreenSpawnPoint.transform; spawnPoint = GameObject.Find("SpawnPoint"); } public void MoveBallToSpawnPoint() { if (spawnPoint is null) { CheckForSpawnPoint(); } StopCoroutine(MoveBall(spawnPoint.transform)); StartCoroutine(MoveBall(spawnPoint.transform)); } public void MoveBallOffScreen() { StopCoroutine(MoveBall(ballStartTransform)); StartCoroutine(MoveBall(ballStartTransform)); } private IEnumerator MoveBall(Transform point) { if (ball.TryGetComponent(out Rigidbody rbBall)) { rbBall.isKinematic = true; yield return new WaitForFixedUpdate(); rbBall.position = point.position; yield return new WaitForFixedUpdate(); rbBall.isKinematic = false; } } } }