Negative Scaling issue

Hello everyone, I am an absolute beginner and just did a few hours of Unity and some tutorials, I try to read a lot but am stuck now:

I try to make a sphere get smaller with every frame and use the following script to achieve that. It is grabbed from a Unity Foundations Tutorial and usually makes the sphere bigger (what works fine), so I thought changing the “+=” to “-=” will do the trick.

So I changed the += in line 13 to -= but it still lets the sphere grow and not shrink… what am I doing wrong, please help me :slight_smile:

public class Tut3 : MonoBehaviour
{
    public Vector3 scaleChange2;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.localScale -= scaleChange2;
    }
}

So, you have a sphere. It has this script on it. Your vector3 values for your scaleChange2 variable are all positive numbers.

When you hit play, what happens?

Also, I’m assuming you only have this script on the sphere and not multiple copies or other scripts.

Thanks for the fast response. When I hit play the sphere increases in size, just like the operater is still “+=”.

There are 2 more scripts which apply to different 3d objects, one is for a slow rotation of a cube while another script lets another sphere increaze in size over time.

Can you post a screenshot of the sphere that has the script above. Show the inspector with the sphere selected.
Note that the other things in the scene are not important to this sphere since it sounds like they don’t interact with it.

Oh, I should also add, that -scale will eventually look like it’s growing because it just scales negatively. It should appear to shrink at first before it starts to “grow” again.

After changing the += to -= in another (earlier made) script that relates to another sphere it suddenly worked partly. For testing purposes I just changed the other problematic script back to += but now this will not work, either both spheres shrink or both spheres increase in size, it seems to be impossible for me to make the one shrink and the other grow.

I used different spheres which were not parent/child related and also different variables (scaleChange and scaleChange2) within the scripts. Why do they seem to mix with each other?

It is really strange and I will try to reproduce it tomorrow because - of course - my PC just crashed and I did not hit save for a while °_°

I’d have to see how you have it setup to tell you more. But if you have two different scripts, they don’t have anything to do with each other. Unless you for some reason have both on the same gameobject doing stuff to scale. So variable name will not make the difference, even if they are the same.

1 Like

Thanks! Would it have any impact if I created a 1st sphere and a script - then duplicating that and deleting the script one the duplicated sphere, after that I created a new similar script with a different name. Could the duplicate process in the begining link those two spheres even if they not chil/parent?

Nope. If the two spheres are not connected in any way in the hierarchy (as you noted, parent/child) then those spheres are not connected. They would not be linked.

1 Like