ScreenRegion.ClampToScreenRegion C# (CSharp) Method

ClampToScreenRegion() public method

Clamps a transform to this screen region and rotates it to face the aimPos
public ClampToScreenRegion ( Vector3 aimPos, Vector3 &clampedPos, Vector3 &clampedDirection ) : float
aimPos Vector3 Aim position.
clampedPos Vector3
clampedDirection Vector3
return float
	public float ClampToScreenRegion( Vector3 aimPos, out Vector3 clampedPos, out Vector3 clampedDirection ) {
		aimPos.z = worldBounds.center.z;

//		Bounds cameraBounds = worldBounds;
//		cameraBounds.center += camera.transform.position;
//		cameraBounds.size *= camera.orthographicSize;

		if( !worldBounds.Contains(aimPos) ) {



			Vector3 origin = worldBounds.center;
			origin.z = aimPos.z;
			Vector3 direction = (worldBounds.center-aimPos).normalized;
			Ray r = new Ray( worldBounds.center - 100f*direction, direction );
			float distance = 0f;

			clampedDirection = direction;

			if( worldBounds.IntersectRay( r, out distance ) ) {
				clampedPos = r.GetPoint(distance);
				return Vector3.Distance(clampedPos,aimPos);
			} else {
				Debug.LogWarning("ClampToScreenRegion ray missed bounds :(");
			}
		}

		clampedDirection = Vector3.up;
		clampedPos = aimPos;
		//transformToClamp.rotation = Quaternion.Slerp( transformToClamp.rotation, Quaternion.identity, 5f*Time.smoothDeltaTime );

		return 0f;
	}