- Home /
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.
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 :)
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.
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
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.
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 Get$$anonymous$$eyDown ins$$anonymous$$d of Get$$anonymous$$ey. 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 ins$$anonymous$$d (ie 0.2f)
In fact, you can definitely have a negative value in scale. It's quite useful for flipping objects on an axis.
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
Follow this Question
Related Questions
LocalScale not working idealy 1 Answer
How to Scale an object up and down over time? 5 Answers
Object's localScale 1 Answer
Multiple Cars not working 1 Answer
How to stop scale reducing from reaching Zero (Solved) 1 Answer