Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need help with my 2D farming game

Discussion in 'Community Learning & Teaching' started by OnionRen, Apr 21, 2017.

  1. OnionRen

    OnionRen

    Joined:
    Apr 21, 2017
    Posts:
    1
    Hi, need some help with my 2D project.

    I am doing a farming-Game basic mobile game about farming and cooking (like farmville2 and overcooked), but I don't know how to collect the grown plants and put on a new inventory, and to make the watered tile go back to normal color after the grown plant.

    Gardening -
    • plant, [DONE]
    • seeds, [DONE]
    • sprout, [DONE]
    • splinkle [DONE]
    • harvest, [needed]
    [Gif Game]

    Here's my real question:

    1.The color of the tile change when i use the sprinkler but how I can make the color change for only 5 secs and then go back to the color that was before?

    Here's a part of my plant controller script:

    Code (CSharp):
    1.            if ((GameMaster.currentTool == "Sprinkler") && (GetComponent<SpriteRenderer>().sprite != nullPlantaObj))
    2.            // with sprinkle, change color to cyan
    3.        {
    4.          
    5.            lote.GetComponent<SpriteRenderer>().color = new Color (0, 1, 1, 1);
    6.            withWater = true; //with water growns plant
    7.        }
    2. How to collect(harvest) the plant after it growns?

    I was using a *public static string currentTool = "something"* to when a click the sprite then change to another sprite (seeds sprite if the tool is a seed, nullPlant Object sprite if the tool is shovel), to collect a plant I going to change to a null sprite after I use a scissors tool, but I need 3 new objects(newPlants sprites) to drop when I harvest a plant, how can I do that?

    [Scripts HERE]

    3. And how to add collected plants to inventory (with quantity)?
     
  2. lizifox

    lizifox

    Joined:
    Feb 18, 2017
    Posts:
    37
    i'm only a beginner myself. this is how i would try to solve this

    1. i would use animations for this. create an animation on your sprinkler that goes from normal color to your sprinkling color in 5 seconds and returns. when the sprinkler is used, you only need to activate this animation.

    2. i would simply spawn the new objects from code at teh location of your plant. check the tutorial on how bullets are spawned from a gun (i think its on the unity website), it will give you code on how to do that.

    3. just create an array that represents your inventory (or a class that contains a list or array). on a new game, instantiate a new inventory. when the player does a thing and gains an item, add it to the inventory list/array. you could have a list that contains all individual objects (e.g. tomate seed nr 07, tomate seed 12, carrot nr 501, ...). or a list that keeps an object type (e.g. tomate seed) and the amount the player has (e.g. tomato seed x 5; carrot seed X 2; ...)
    depends on your game which is better. i would guess the second.