Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Sequential Buttons Lists

Discussion in 'Scripting' started by metamorphist, Mar 31, 2016.

  1. metamorphist

    metamorphist

    Joined:
    Mar 15, 2014
    Posts:
    77
    Looking for a way to store sequence of buttons,
    somewhat like an array of properties that belongs to a particular skill.

    Like, Skill A has Damage x, distance n, buttons A-B-B-C, animation sequence DELTA executed with a particular method and so on.
    And the skills also belong to a particular unit inside another lists.

    Help?
    I hope i am wording it out nicely.
     
  2. Craig8726

    Craig8726

    Joined:
    Jul 5, 2013
    Posts:
    79
    You could write a class that holds the data you need and then create a list of that class for all instances of it.

    eg.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. [System.Serializable]
    6. public class Skill
    7. {
    8.     public string skillName;
    9.     public int damage;
    10.     public int distance;
    11.     public Button A;
    12.     public Button b;
    13.     //etc
    14.  
    15. }
    example of list of the skill class instances.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class SkillList : MonoBehaviour
    7. {
    8.     public List<Skill> skillList = new List<Skill>();
    9.  
    10.     void Start()
    11.     {
    12.         // you can generate the skill list at start
    13.  
    14.         Skill newSkill = new Skill ();
    15.         newSkill.skillName = "insert whatever name";
    16.         newSkill.damage = 10;
    17.         newSkill.distance = 5;
    18.         newSkill.A = Resources.Load<Button> ("File path for your button prefab");
    19.         newSkill.b = Resources.Load<Button> ("File path for your button prefab");
    20.  
    21.         skillList.Add (newSkill);
    22.     }
    23.  
    24. }
    hope this helps you out and broadens your knowledge :)
     
    metamorphist likes this.
  3. metamorphist

    metamorphist

    Joined:
    Mar 15, 2014
    Posts:
    77
    Hmmm, yes thank you it does broaden my knowledge... although i am still tad slightly intimidated by Lists and Ditionaries use or designing....
    However,my skill list all comes in the animation clip already.....
    Separated into different states which i currently am not sure if i were to name them according to its ability name, or some generic names so it can be override easily but may require me to switch the clips with scripting in game....