bool inView() { if (!view) { return(true); //If there is no script to make the camera follow the player, then assume we are in view } else { if (view.isActiveAndEnabled) { return(view.insideView(conversationCenterPoint, outsideCameraBuffer.x, outsideCameraBuffer.y)); } else { return(true); //If the component is there but disabled, then we aren't moving the view so we'll just return true; } } }
//Plays a sound effect if the specified position is within the camera's view. If cameraFollowPlayer does not exist then it will play the sound every time. //Buffer is added to the boundaries of the camera so pos can be a little outside of the view (negative buffer) or needs to be a little inside of the view (positive buffer) //By default the pos can be within one unit ouside of the view and the sound will still play. public void PlayIfOnScreen(AudioClip clip, Vector2 pos, float buffer = -1f, float randomizePitchMin = 1, float randomizePitchMax = 1) { if (!cameraFollow) { cameraFollow = Camera.main.GetComponent <cameraFollowPlayer>(); } bool play = true; if (cameraFollow) { if (!cameraFollow.insideView(pos, buffer, buffer)) { play = false; } } if (play) { Play(clip, randomizePitchMin, randomizePitchMax); } }