- Home /
Question by
Hobbit9797 · Oct 03, 2013 at 03:09 PM ·
c#gameobjectscale
Scaling a GameObject c#
I´m trying to rescale an object at runtime but I can´t find a working method. :(
transform.localScale.x= health/100;
This gives the error: Assets/Assets/Scripts/enemy.cs(15,27): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.localScale'. Consider storing the value in a temporary variable
Comment
$$anonymous$$aybe try :
transform.localScale = Vector3(health/100.0,transform.localScale.y,transform.localScale,z);
Best Answer
Answer by AjayKhara · Oct 03, 2013 at 03:14 PM
You have to do it this way in c#.
transform.localScale = new Vector3(health/100,transform.localScale.y,transform.localScale.z);
Please accept it as an answer and vote it up if it helped you out. Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613115237im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How should one resize a gameobject? 1 Answer
Distribute terrain in zones 3 Answers
[Solved] SteamVR 2.0 Unity Plugin scale gameobject with 2 hands 2 Answers
Extend only a part of an object unity 1 Answer
Multiple Cars not working 1 Answer