void Awake() { if (_instance == null) { _instance = this; DontDestroyOnLoad(this); } else { if (this != _instance) { Destroy(this.gameObject); } } }
//private void OnDrawGizmos() { // Gizmos.color = Color.blue; // Gizmos.DrawWireSphere(transform.position, AcceptanceCollisionRadius); // Gizmos.DrawLine(transform.position, transform.position + transform.forward); //} private void CheckForHit() { // Get the current information of the tracked object Vector3 normal = transform.forward; Vector3 ab = trackingObject.position - transform.position; float proj = Vector3.Dot(ab, normal); // Is the ball in front (Assume being inside as in front) bool nowInFront = proj >= 0; // Check to see the distance from the normal Vector3 distanceVec = ab - (normal * proj); float distSquared = distanceVec.sqrMagnitude; // Is the ball is within range of an acceptable hit bool nowInRange = distSquared <= (AcceptanceCollisionRadius * AcceptanceCollisionRadius); if (PublicScript.UseTimer(ref TimeBetweenHitsSubtract, TimeBetweenHits)) { canHitBall = true; } // A hit has been detected! if (inRange && inFront != nowInFront) { Debug.Log(TimeBetweenHitsSubtract); if (canHitBall) { HandleCollisionLogic(); canHitBall = false; } } // Set the current values as the previous ones for the next hit detection inRange = nowInRange; inFront = nowInFront; }