[NEWBIE] Scaling issue

Hey guys! Glad to be a part of the community. I’ve watched over 100 hours of dev builds and all that fun stuff to get somewhat prepared, and now I’m finally taking my first steps into the world of development. I’m not a total beginner to scripting, however any new engine/language is going to take some practice and dumb questions.

Basically, I’ve created a “Playground” level in which I can mess around with code and get the hang of things. As a starting point, I’ve decided to start with messing around with vectors.

I have a sphere that’s 5x5x5, and I’m trying to scale it to 10x10x10, then back down to 5x5x5.

Unfortunately, my code will only increase the sphere (seemingly) infinitely. Here’s what I have so far, along with questions regarding some of the parts:

using UnityEngine;
using System.Collections;

public class Growth : MonoBehaviour {

    public int i;
    public float growthMult = 1.0f;

    // Use this for initialization
    void Start () {
 
    }
 
    // Update is called once per frame
    void Update () {

        for (i = 5; i <= 10; i++) {
         
            transform.localScale = new Vector3 (i, i, i) * growthMult * Time.deltaTime;
             
        }

        for (i = 10; i > 5; i--) {
            transform.localScale = new Vector3 (i, i, i) * growthMult * Time.deltaTime;
        }
    }
}

This is definitely scaling it. However it is, for some reason, going to an extremely small number. Really fast, might I add.

What do you guys think? Any better way at approaching this?
Again, I’m completely new to actually doing things in Unity. Watching so many videos and tutorials weren’t necessarily to retain, but to inspire and get to know the basics/syntax. (Never used C# before.)

the problem with your code is you are putting a loop into Update.

A loop will run until completion before the next code block is run, so what your code will do is make it big, make it small in one frame. over and over.

bool increase = true;
float size = 5;

void Update()
{ 
  if(increase)
  {
    size += Time.deltaTime;
    if(size > 10)
       increase = false;
  }
  else
  {
      size -= Time.deltaTime;
      if(size < 5)
         increase = true;
  }
  
  transform.localScale=newVector3(size,size,size);

}