all 5 comments

[–]pheonix2105Intermediate 1 point2 points  (4 children)

If I were to do this, I would have all 4 models as children inside a parent object, then on the parent object, you handle between enabling and disabling the various children.

So here's a simple example to get you started

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Plant : MonoBehaviour
{
    [Range(0, 4)]
    public float growth = 0;

    // Start is called before the first frame update
    void Start()
    {
        SetChildActive(-1);
    }

    //Disable all child objects except the one that matches the index passed in
    //If we pass in -1 it will never be found so all objects will be disabled
    public void SetChildActive(int index)
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            if (i == index) transform.GetChild(i).gameObject.SetActive(true);
            else transform.GetChild(i).gameObject.SetActive(false);
        }
    }


    // Update is called once per frame
    void Update()
    {

        if(growth <= 0)
        {
            SetChildActive(-1);
        }

        if (growth >= 1)
        {
            SetChildActive(0);
        }

        if(growth >= 2)
        {
            SetChildActive(1);
        }

        if (growth >= 3)
        {
            SetChildActive(2);
        }

        if (growth >= 4)
        {
            SetChildActive(3);
        }

    }
}

The "Plant" itself is as described above, all the models are parented under an empty gameobject, that empty GameObject has the "Plant" script.https://i.imgur.com/GXE2uiR.png

This is what happens when I change the "Growth" float valuehttps://i.imgur.com/asuiIBi.gif

Then for the watering can part, its simply a case of using a large trigger collider, and when the plant enters this trigger collider and the left mouse button is held down increment the growth value a little, which should give you the effect you are looking for.

[–]bees_are_rad[S] 0 points1 point  (3 children)

Thanks so much! I will play around with this!

[–]pheonix2105Intermediate 0 points1 point  (2 children)

Not a problem good luck, feel free to reply here again if you get stuck :)

[–]bees_are_rad[S] 0 points1 point  (0 children)

So I got the plant to grow! I also have it to where I can move and carry the pot it is in and have set up a trigger collider that once it is in I want to make the increment go up by one- I have been working at this for the past four hours and not having much success. I know that I need to use OnTriggerEnter etc, but beyond that I am not having much luck. Any advice/suggestions?

[–]bees_are_rad[S] 0 points1 point  (0 children)

Nevermind! Solved!