- Home /
Question by
miramaslow · Aug 10, 2017 at 04:37 AM ·
c#dragginglocalscale
Problems with GameObjects localScale
I'm having a problem when I'm scalling the walls of the gameObjects, below image illustrates the problem.
The wall seems re scale on themselves whenever I clicked on it, and it happens on both sides. The code seems cannot retrieve the original scale of the object. I tried rescalling the objects in the inspector and stuff, but I can't seem get it to work. I don't know what is happening.
Here's the code I'm using
if (isMouseDragging)
{
//tracking mouse position.
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float dist;
plane.Raycast(ray, out dist);
Vector3 v3Pos = ray.GetPoint(dist);
if(getTarget.CompareTag("LeftRightWall") && getTarget.transform.childCount == 1)
{
foreach (GameObject frontWall in GameObject.FindGameObjectsWithTag("FrontWall"))
{
Vector3 v3Scale = frontWall.transform.localScale;
frontWall.transform.localScale = new Vector3(v3Pos.x*2.0f , v3Scale.y , v3Scale.z);
}
foreach (GameObject roofAndFloor in GameObject.FindGameObjectsWithTag("Floor"))
{
Vector3 v3Scale = roofAndFloor.transform.localScale;
roofAndFloor.transform.localScale = new Vector3(v3Pos.x*2.0f , 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);
}
if(getTarget.CompareTag("FrontWall") && getTarget.transform.childCount == 1)
{
foreach (GameObject leftRightWall in GameObject.FindGameObjectsWithTag("LeftRightWall"))
{
Vector3 v3Scale = leftRightWall.transform.localScale;
leftRightWall.transform.localScale = new Vector3(v3Pos.z*2.0f , v3Scale.y , v3Scale.z);
Debug.Log("clicked FrontWall");
}
foreach (GameObject roofAndFloor in GameObject.FindGameObjectsWithTag("Floor"))
{
Vector3 v3Scale = roofAndFloor.transform.localScale;
roofAndFloor.transform.localScale = new Vector3(v3Scale.x , v3Pos.z*2.0f , v3Scale.z);
}
v3Pos.y = getTarget.transform.position.y;
v3Pos.x = getTarget.transform.position.x;
getTarget.transform.position = v3Pos;
getTarget.transform.GetChild(0).gameObject.transform.position = new Vector3(v3Pos.x, v3Pos.y, -v3Pos.z);
}
Thanks in advance!
cube.gif
(36.6 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612132403im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scale object based on another object's position 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to Position the object perfectly with the Screen Bounds 0 Answers
Scale objects marginally! 0 Answers