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

Help Checking A List

Discussion in 'Scripting' started by DRRosen3, Oct 24, 2014.

  1. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    I'm using a List to store a player's attacks. I want to at all times have 4 buttons in my battle GUI, even if the player doesn't yet know 4 attacks. I tried doing something like:

    if(GameInformation.playersAttack[0] != null){
    GUI.Button(new Rect(Screen.width - 100, Screen.height - 50, 75, 30), GameInformation.playersAttack[0].AttackName);
    }else{
    GUI.Button(new Rect(Screen.width - 100, Screen.height - 50, 75, 30), "EMPTY");
    }

    Obviously this didn't work. Can somebody point me in the right direction for what I need to make my "if statement" say to check the index of the List that I want to check?
     
  2. jabez

    jabez

    Joined:
    Nov 2, 2013
    Posts:
    26
    Hello there, you could do this a few ways but try
    Code (CSharp):
    1.  
    2.       if(GameInformation.playersAttack[0]){
    3.  
    4.             Debug.Log("Found");
    5.                     }else{
    6.             Debug.Log("Empty");
    7.                     }
    I would do a loop & create a list of rects in your game information for each attack then do something like this
    Code (CSharp):
    1. for (int i = 0; i < GameInformation.playersAttack.Count; i ++) {
    2.             if (!GameInformation.playersAttack [i]) {
    3.                 GUI.Button (GameInformation.playersAttack [i].AttackRect, GameInformation.playersAttack [i].AttackName);
    4.                         } else {
    5.                 GUI.Button (GameInformation.playersAttack [i].AttackRect, "EMPTY");
    6.                         }
    7.  
    8.                 }
    9.         }
    oh btw do you even have a script that assigns the animation to null? how do you even detect that the animation has stopped?
    Take it easy.
     
    Last edited: Oct 24, 2014
  3. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Hmm. I never even thought about thinking of the index of the array as bool.

    I'll give both a shot later tonight. (Too busy at work today to be playing around with my project unfortunately.)

    And as far as the animation to the "EMPTY" (as I assume that's what you meant by null)...there won't be one. The button will be clickable, but nothing will happen. It's a turn-based combat system. So it's not like the player will be sitting there bashing on the "EMPTY" button expecting something to happen and the enemy is just attacking them non-stop. The order is:
    1. Player Chooses Attack
    2. (Simultaneously) Enemy AI Chooses Attack
    3. (Animation happens during this state.) Attacks are carried out in order based on player's/enemy's speed & damage is applied.
    4. Status effects (if any) apply their damage here.
    5. Repeat.