- Home /
How to zoom in line renderer using the camera
My goal is to make sure that the thickness of the Linerenderer remains the same even when camera enlarged. I'd like to enlarge the Linerenderer using the camera. i use render texture to draw a linerenderer inside the canvas. Canvas and camera are related to the z-axis. So I made a button and set the width of the linerenderer using the z-axis of the camera when I pressed the button. However, the results showed that there was a slight thickness error. so i ask you is it right? or is it wrong?
public class ButtonClick1 : MonoBehaviour { public GameObject makeShapes; public GameObject ImageObject; public Camera mapCamera; ImageChange imageChange; MakeShapes makeshapes; float baseWidth = 1.0f;
new Camera camera;
RectTransform rect;
float baseFov;
Vector3 dis;
float zDistance;
Vector3 baseposition;
private void Start()
{
makeshapes = makeShapes.GetComponent<MakeShapes>();
imageChange = ImageObject.GetComponent<ImageChange>();
camera = mapCamera.GetComponent<Camera>();
rect = mapCamera.GetComponent<RectTransform>();
baseFov = camera.fieldOfView;
baseposition = rect.localPosition;
zDistance = (camera.transform.position.z - makeshapes.transform.position.z);
dis = (Vector3.forward * zDistance);
dis = Vector3.Normalize(dis);
}
public void Button1()
{
makeshapes.ChangeWidth(baseWidth);
Debug.Log("1 " + baseWidth);
rect.localPosition = new Vector3(baseposition.x, baseposition.y,zDistance* baseWidth);
}
public void Button2()
{
makeshapes.ChangeWidth(baseWidth* 0.666667f);
Debug.Log("2 "+baseWidth * 0.666667f);
rect.localPosition = new Vector3(baseposition.x, baseposition.y, zDistance * 0.666667f);
}
I can't figure it out even if I look it up on web surfing. Please let me know if there is a better way.
this is part of my code