6

How can I increase / decrease the size of objects in Unity?

Example:

public GameObject sprite;
public  float scale = 2.0f;

void ScaleResolution()
{
    sprite = sprite*scale; //epic string!
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • They don't need to be public. Use [SerializeField]. –  Feb 07 '14 at 21:14
  • @Jessy: [The Unity documentation](http://docs.unity3d.com/Documentation/ScriptReference/SerializeField.html) actually recommends just keeping them public. – BlueRaja - Danny Pflughoeft Feb 07 '14 at 23:16
  • I don't see the recommendation. –  Feb 08 '14 at 02:50
  • @Jessy The first sentence is *"You will almost never need this"*... – BlueRaja - Danny Pflughoeft Feb 09 '14 at 04:35
  • That statement is incorrect; you will technically never need the SerializeField attribute, the same as you will never need private fields. However, this serialization behavior was designed for Uniy's "JavaScript", where the default access of a field is public, and there are no properties. If you're using C#, properties make it easy to avoid sacrificing your code quality by making all serialized fields public. –  Feb 09 '14 at 15:10

2 Answers2

22

It's a property of the transform component

sprite.transform.localScale = new Vector3(2.0f, 2.0f, 2.0f);
BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
2

Position, Rotation & Scale are properties of transform so you need to modify if as follows:

public GameObject sprite;

public float scale = 2.0f;

void ScaleResolution()

{

sprite.transform.localScale = new Vector3(scale, scale, scale);
}