I want the player to see an object in their peripheral vision and when they turn toward it - and object is now in center of the camera - the renderer is turned off and the object now spawns in another area of the screen (or I have multiple objects or it turns back on when player turns away - I plan to use all three). I would like this to be minimally 3D but don’t want to use triggers - just center of view. I know how to turn renderer on and off with mouse but my limited coding skills have me stumped here. Working on raycasts now… Any help most appreciated.
What about something using Camera.WorldToScreenPoint
?
void Update()
{
p = Camera.main.WorldToScreenPoint(transform.position);
if (Mathf.Abs(0.5-p.x) < 0.25 && Mathf.Abs(0.5-p.y) < 0.25)
{
this.renderer.enabled = false;
}
else
{
this.renderer.enabled = true;
}
}
The center of the screen should be (0.5, 0.5)
and the edges should be at 0
and 1
, so you can just check if it’s in some range smaller than 0-1.