increasing the scale of a Object by a non integer number

I’m trying to increase the scale of an object by .1 or .1, but it only allows a scale increase of 1 from what i’ve been tring.

A snippet of the code:
void Update () {
if (experience >= requiredExperience) {
experience = 0;
level += 1;
requiredExperience *=2;
attributePoints += 5;
transform.localScale += new Vector3 (1,1,1);

Use code tags:

Also, localScale is a Vector3, it stores floats, it should easily support incrementing by fractional values.

What sort of error are you getting?

You need to add “f” at the end of your floating point numbers, as in “.1f”. This is because in C#, floating point numbers are seen as the “double” type by default, whereas Vector3 is a struct of three “float” type floating point numbers. The little “f” at the end of a number denotes that it is a float, not a double.

If you want to know more about float and double and value types in general (and you should, if you want to take programming seriously), read up on 'em.

2 Likes

I’ve tried those methods but this is what I get. And sorry I saw the code button on another forum but didn’t see it here.

    void Update () {
        if (experience >= requiredExperience) {
            experience = 0;
            level += 1;
            requiredExperience *=2;
            attributePoints += 5;
            transform.localScale += new Vector3 (.1,.1,.1);

        }

You were right Thomas, adding the F at the end worked just fine. Thank you. I’m used to coding is JS and Java so I was a bit lost why this didn’t work. I’m a bit new to C sharp, but after I get the syntax down, it should be easy.

1 Like