x


Unity Scaling an object from scripts

my script is this...When i scale the object it transform.position gets the same but in the world it shows at different position.

using UnityEngine; using System.Collections;

public class size1 : MonoBehaviour {

// Update is called once per frame

void Update() {






    if(abc.Ball1>900 && abc.Ball1<=1000)
    {

       transform.localScale=new Vector3(1.5f,1.5f,1.5f);
    }
    else if(abc.Ball1>800 && abc.Ball1<=900)
    {   
       transform.localScale=new Vector3(1.3f,1.3f,1.3f);
    }
    else if(abc.Ball1>700 && abc.Ball1<=800)
    {   
       transform.localScale= new Vector3(1.1f,1.1f,1.1f);
    }
    else if(abc.Ball1>600 && abc.Ball1<=700)
    {   
       transform.localScale= new Vector3(.9f,.9f,.9f);
    }
    else if(abc.Ball1>500 && abc.Ball1<=600)
    {   
       transform.localScale=new Vector3(.7f,.7f,.7f);
    }
    else if(abc.Ball1>400 && abc.Ball1<=500)
    {   
       transform.localScale=new Vector3(.5f,.5f,.5f);
    }
    else if(abc.Ball1>300 && abc.Ball1<=400)
    {   
       transform.localScale=new Vector3(.4f,.4f,.4f);
    }
    else if(abc.Ball1>200 && abc.Ball1<=300)
    {   
       transform.localScale= new Vector3(.3f,.3f,.3f);
    }
    else if(abc.Ball1>150 && abc.Ball1<=200)
    {   
       transform.localScale= new Vector3(.2f,.2f,.2f);
    }
    else if(abc.Ball1>=50 && abc.Ball1<=150)
    {   
       transform.localScale=new Vector3(.1f,.1f,.1f);
    }
    else if(abc.Ball1>0 && abc.Ball1<50)
    {   
       transform.localScale= new Vector3(0f,0f,0f);
    }

}

}

more ▼

asked Dec 21 '11 at 11:10 AM

haider1515 gravatar image

haider1515
41 16 21 24

probably it is with the pivot point of the gameObject u r using?!

check where the pivot point is !!

Dec 21 '11 at 11:23 AM flamy

pivot cannot be changed in unity

Dec 21 '11 at 12:02 PM haider1515

i have hacked its pivot from gameobject it give the same result

Dec 21 '11 at 12:03 PM haider1515

If you rotate the object around it's Y after you scale it you'll see where the pivot actually is.

Dec 21 '11 at 01:11 PM HHameline
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The scaling happens always around the objects pivot point. The position is not affected when you change the scale. That sounds like you have set the pivot mode to "center" instead of pivot:

pivot mode image

If the mode is set to "center" it shows the "handle" at the objects center instead of its pivot

You are right, you can't set the pivot point in Unity, but in the application you created the object. I'm not an artist so i can't advise you how ;)

more ▼

answered Dec 21 '11 at 05:26 PM

Bunny83 gravatar image

Bunny83
45.2k 11 49 206

i changed the pivot in maya and import it back...thanx

Dec 22 '11 at 08:07 AM haider1515
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3726
x884
x386
x81

asked: Dec 21 '11 at 11:10 AM

Seen: 2298 times

Last Updated: Dec 22 '11 at 08:07 AM