Hi there
Can anyone tell me how I can set the X value of a Camera Normalized Viewport Rect with code? I’m making a window-style icon so that the user can drag my camera around, bit I can’t seem to find this anywhere??? It must be something simple I’m missing.
Thanks
just change it. But as its a rect, you must copy it out to a Rect object, change it on this temporal one and reassign it especially if you work with C#
1 Like
Hi Dreamora
void OnMouseDrag()
{
targetCam1.GetComponent<Camera>().pixelRect.x = Input.mousePosition.x;
}
This is saying that rect is not a variable?
I don’t know if this is what you meant, but this is giving me some other error:
void OnMouseDrag()
{
Rect r = new Rect();
r.x = Input.mousePosition.x;
targetCam1.GetComponent<Camera>().rect = r;
}
Error:PPtr cast failed when dereferencing! Casting from Camera to GameObject
Ok, so it is sorted by changing the type of targetCam1 to Camera and not GameObject and adapting that line accordingly. I will post the final script when I have made the adjustments if someone else also want to do this.
Thanks Dreamora for always helping