How to set far and near clipping plane of camera with scripting
I have a script attached to a player that creates a main camera when the game is played putting the camera as a child of the player object. Then i want to refer to that camera object and set values for the near and far clipping planes of that camera to reduce draw distance.
I tried this but it doesn't work:
public void start()
{
camera = transform.Find("$$anonymous$$ain Camera").gameObject;
if(camera != null)
{
float Camera,farClipPlane = 100.0F;
}
}
Answer by AlucardJay · Oct 26, 2016 at 12:41 PM
https://docs.unity3d.com/ScriptReference/Camera.html
https://docs.unity3d.com/ScriptReference/Camera-nearClipPlane.html
https://docs.unity3d.com/ScriptReference/Camera-farClipPlane.html
What i want to do is change the farClipPlane variable of a child camera object that gets created at runtime. And i don't know how to code that.
Ween you create the camera, store a reference to it in a variable. This saves the problem of finding it again.
Once you have a reference pointer to the camera, you can access/modify all the camera properties.
// creating by instantiating prefab :
GameObject cameraObject = (GameObject)Instantiate( myCameraPrefab );
Camera myCamera = cameraObject.GetComponent< Camera >();
// creating by adding component :
Camera myCamera = gameObject.AddComponent< Camera >();
// now you have a reference pointer to the camera, modify properties :
myCamera.nearClipPlane = 0.05f;
myCamera.farClipPlane = 100f;
Your answer
Follow this Question
Related Questions
Have object always lookAt camera 1 Answer
randomly Instantiate items 0 Answers
Rotating a player around the centre with touch controls. 0 Answers
How do you continuously rotate an object? 1 Answer
Timer wont work 0 Answers