Despite an hour or so of Googling I can't seem to figure out how to calculate the scale factor based on distance. Here's the illustration of my problem.
I've tried manipulating the x values and such, but until now I still cannot figure it out. Here's the snippet:
Vector3 v3Scale = frontWall.transform.localScale;
frontWall.transform.localScale = new Vector3(v3Pos.x*2.0f , v3Scale.y , v3Scale.z);
Any ideas? Thanks in advance!
UPDATE:
if(getTarget.CompareTag("LeftRightWall") && getTarget.transform.childCount == 1)
{
float translate = getTarget.transform.position.x - getTarget.transform.GetChild(0).gameObject.transform.position.x;
Debug.Log("value :"+translate);
foreach (GameObject frontWall in GameObject.FindGameObjectsWithTag("FrontWall"))
{
Vector3 v3Scale = frontWall.transform.localScale;
float scaleFactor = translate/frontWall.transform.localScale.x;
frontWall.transform.localScale = new Vector3(translate , v3Scale.y , v3Scale.z);
}
v3Pos.z = getTarget.transform.position.z;
v3Pos.y = getTarget.transform.position.y;
getTarget.transform.position = v3Pos;
getTarget.transform.GetChild(0).gameObject.transform.position = new Vector3(-v3Pos.x, v3Pos.y, v3Pos.z);
}
The LeftRightWall is the ones that I drag on the picture, with another vertical line as its child. The FrontWall is the horizontal line that is stretched when the LeftRightWall is dragged. Hope its clear enough. Thanks
UPDATE: This is the closest one from what I'm trying to achieve... ((
Here's the code:
float translate = getTarget.transform.position.x - getTarget.transform.GetChild(0).gameObject.transform.position.x;
Debug.Log("value :"+translate);
foreach (GameObject frontWall in GameObject.FindGameObjectsWithTag("FrontWall"))
{
Vector3 v3Scale = frontWall.transform.localScale;
frontWall.transform.localScale = new Vector3(translate+v3Pos.x, v3Scale.y , v3Scale.z);
}
UPDATE: This is what I'm able to do so far, thanks to the answer below. However I still don't know why the other side of the panel is behaving like that. The scale of horizontal lines also shrinks when I click on the vertical line.
This is the updated code:
ray = mainCamera.ScreenPointToRay(Input.mousePosition);
float dist;
plane.Raycast(ray, out dist);
Vector3 v3Pos = ray.GetPoint(dist);
if(getTarget.CompareTag("LeftRightWall") && getTarget.transform.childCount == 1)
{
float translate = getTarget.transform.localPosition.x - getTarget.transform.GetChild(0).gameObject.transform.position.x;
Debug.Log("value :"+getTarget.transform.GetChild(0).gameObject.transform.localPosition.x);
foreach (GameObject frontWall in GameObject.FindGameObjectsWithTag("FrontWall"))
{
Vector3 v3Scale = frontWall.transform.localScale;
float scaleFactor = (translate/v3Scale.x);
frontWall.transform.localScale = new Vector3(v3Scale.x*scaleFactor, v3Scale.y, v3Scale.z);
}
v3Pos.z = getTarget.transform.localPosition.z;
v3Pos.y = getTarget.transform.localPosition.y;
getTarget.transform.localPosition = v3Pos;
getTarget.transform.GetChild(0).gameObject.transform.position = new Vector3(-v3Pos.x, v3Pos.y, v3Pos.z);
}