• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Tibie · Dec 09, 2012 at 08:45 PM · c#vector3scalelocalscaletranform

problem Changing Scales in Script -C#

Hey , does anybody know if its possible to change Scale through Script in C# ?

I tried by doing

if(Input.GetKey(KeyCode.C)){

transform.LocalScale = new Vector3 (0,-1,0);

}

when it runs this , the Gameobject Gets removed from the scene .

am i doing something wrong here ? or maybe its not possible ?

Thx.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by GooseNinja · Dec 10, 2012 at 01:58 AM

Take a look at your `new Vector3 (0,-1,0);`

When you press C your object goes from (1, 1, 1) (I'm guessing)

to (0, -1, 0).. Making the X and Z invisible.

try writing `transform.LocalScale = new Vector3 (1,-1,1);` to see if that works :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Eric5h5 · Dec 09, 2012 at 10:27 PM

You can't have a 0 scale on more than one axis, since that makes it a 1-dimensional object and therefore not visible.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Tibie · Dec 10, 2012 at 02:01 AM

Ahhh , reading this again ...... was a pretty dumb question actually

i should probably just let it play an animation instead of messing with scales

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by shane.rachel · Dec 09, 2012 at 10:16 PM

Scale refers to the size of the gameobject. Your script won't work however because you have x=0, z=0 and here's the killer y= -1. You can't have a negative value in scale, that means not only does your gameobject not exist, but it actually has negative volume.

try changing the values to positive floats.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shane.rachel · Dec 09, 2012 at 10:22 PM 0
Share

oh yeah, and you'll want to set a condition to that most likely. Your script, if left alone, will multiply your gameobject by your scale every time you press the C button.

you might also consider using GetKeyDown instead of GetKey. The faster your cp is, and the more frames it updates per second, you could see a cube going from 1 cubic unit to 100+ cubic units in one button press.

If you want the scale to decrease, enter decimals instead (ie 0.2f)

avatar image Eric5h5 · Dec 09, 2012 at 10:25 PM 1
Share

In fact, you can definitely have a negative value in scale. It's quite useful for flipping objects on an axis.

avatar image shane.rachel · Dec 09, 2012 at 10:39 PM 0
Share

I've never tried, in any case having 0 for x and y would give an invisible object regardless of the scale on z.

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

How to Scale an object up and down over time? 5 Answers

Object's localScale 1 Answer

LocalScale not working idealy 1 Answer

Multiple Cars not working 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges