Search Unity

UI Images; Easy to understand but difficult when looking for a specific task with it.

Discussion in '2D' started by CptBubbleButt, May 10, 2018.

  1. CptBubbleButt

    CptBubbleButt

    Joined:
    Apr 24, 2018
    Posts:
    27
    Hello All,

    I am on the forums because I have tried everywhere else but there doesn't seem to be any tutorial or explanation video on what I would like/need to do, while using the UI or GUI Images. So hopefully someone who looks at this thread can help me with my task at hand.

    I am building a strategic/survival game where the Player has two control a group of people and try to survive the world around them; by collecting resources and keeping the moods high among the group. However, I decided to add a new mechanic in the game that adds difficulty and strategy to the game - which is called an Action Point System. Similar to a game like Hearthstone, the player will be limited by how much they can do each day (turn) depending on how much AP they have left. For example: The player starts off with three AP and two of the main buildings cost that much AP (alongside the cost of materials) meaning the player has to choose which building to prioritise. Simple concept right?

    Well for the coding part I can't seem to find a way to get this plan into action. so I am calling to you to see if you can help me get started with tackling this issue. The concept for the code is as follows:

    - The player starts off with 3 AP, meaning there will be three AP at the bottom middle of the screen.
    - When the player purchases a building, the cost of the AP will take away from the current amount of AP that the player has available, which means the AP on the screen will visually disappear and the building is ready to be placed.

    - The Total AP will be reset to the maximum amount the player can spend each day.

    - [For the future] Some buildings will give the player extra AP per day.

    If someone could help out with where to look or how to approach this, I would greatly appreciate it.

    Thank you,

    -Jack
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    So, you just want a cost per building and the AP the player has. Buying/constructing a building edits the user's AP.
    For the giving extra AP, sounds like some time based or turn based "payout" system.

    I'm not sure how else to provide an answer at the moment. Have you tried writing anything, yet?
     
  3. CptBubbleButt

    CptBubbleButt

    Joined:
    Apr 24, 2018
    Posts:
    27
    I have tried increasing the number of images like this:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class ActionPoints : MonoBehaviour {
    7.         private Image ActionPoints;
    8.         private int Example = 1;
    9.        
    10.     // Use this for initialization
    11.     void Start () {
    12.        
    13.  
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.                if (Input.KeyDown(KeyCode.I)){
    19.                    Example ++;
    20.               }
    21.              
    22.               if (Example >= 0) {
    23.                   ActionPoints ++;
    24.               }
    25.  
    26.     }
    27. }
    But obviously, when reading the syntax errors the operator "++" isn't used in UnityEngine.UI... Wait a minute, does it being a "simple" image have an issue? As with health bars you'd have the "fill" parameter chosen, but would something like the "tiled" parameter make it so the code is checking the number is correct for that tile, therefore increasing the amount of images on the screen?
     
  4. CptBubbleButt

    CptBubbleButt

    Joined:
    Apr 24, 2018
    Posts:
    27
    I also tried to make a code based around this video tutorial:
    as well but I don't know how to make it so when the value is above the maximum value it'll add another image.
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, you'd have to assign a value to the image fill amount, I would think.
    If each AP point was represented as an image, you could also consider having them in a horizontal layout group, and simply add/subtract them as they're earned/spent. I suppose that would depend on the maximum number a player could have at any given time, as presumably too many would look bad/silly (unless you added like "x10" or something to shorten the length).

    Is there any other specific question that you have?
     
  6. CptBubbleButt

    CptBubbleButt

    Joined:
    Apr 24, 2018
    Posts:
    27
    Um no not at this current time, I shall definitely try it out as it would make a sense to assign the image a value. I will try figuring it out then I will send you a message if I get stuck at all.