• 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
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

People who like this

0 Show 0
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

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
advancexz
Tyler32123

People who like this

2 Show 0 · 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

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
shane.rachel

People who like this

1 Show 0 · 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

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

People who like this

0 Show 0 · 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

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

People who like this

0 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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

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

Distribute terrain in zones 3 Answers

Object's localScale 1 Answer

LocalScale not working idealy 1 Answer

How to stop scale reducing from reaching Zero (Solved) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges