- Home /
 
Displaying a List, One item at a time, where items can be added Simultaneously
I am creating a match3+battle (think Puzzles & Dragons) that has a scrolling damage display. Yes I did look at other scrolling combat systems for Unity, but none seem to address my problem (they all ignore it or it doesn't apply to them).
There is the possibility of a near-simultaneous match/damage being recorded which is giving me fits. For example, due to randomness, you might get a simultaneous horizontal match3 on part of the board, and a vertical match3 elsewhere on the board as pieces fall. This results in damage being applied from two different places at the same time, which results in the scrolling damage text displaying on top of itself.
In theory I want to:
Record the damage produced by the match to a List (this I can do);
Have it show the damage output above the character in a scrolling/combat style (this I can also do);
If there is more than one item in the List at a time, show one first, small delay, and then the next (this I can't seem to do).
1 and #2 I can already do. It's #3 I need help on! :)
Roughly speaking, I do something like this to Add to the List
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class GameManager : MonoBehaviour 
 {    
 
 public List<int> damageList = new List<int>();
 public int damage;
 public void AddDamage()
 {
     int temp = 10 + (timesInaRow * multiplier); //+damage on successive combos
     damage += temp;
     damageList.Add (temp);
 }
 
               What I'm really struggling to do is figure out how to get it to only display one item in the List at a time. When I do a forloop like the following, it works fine so long as there's no simultaneous match, but if there is a simultaneous match, it will display the damage over itself (looks ugly). Any help on how to read off a list, one at a time, with a pause in between?
 public void DamageText()
 {
     for (int i = 0; i < damageList.Count; i++)
     {
         Animation anim;
         damage = -damage;
         damageText.guiText.text = damage.ToString();
         Instantiate(damageText, new Vector3(0.8f,0.8f,0), Quaternion.identity);
         anim = GameObject.FindGameObjectWithTag ("Enemy").GetComponent<Animation>();
         anim.animation.Play ("dragon_hit_front");
         damageList.RemoveAt(0);
         damage = 0;
     }
 }
 
              You could adapt my answer here which has spacing time: http://answers.unity3d.com/questions/258368/who-killed-who-scrolling-gui-text.html
Thanks this worked! Thanks to the other replies as well, all helpful.
Answer by yannru.cheng · Feb 20, 2014 at 05:57 AM
Try using a coroutine and yield for a frame or few seconds if you want
http://docs.unity3d.com/Documentation/Manual/Coroutines.html
Answer by MattMorris · Feb 20, 2014 at 06:22 AM
Id use time.deltaTime so:
 float timeInterval = 2.0f;
 int index = damageDelt.Length;
 
 timeInterval -= time.deltaTime;
 
 if(timeInterval <= 0)
 {
     if(index > 0)
     {
         display(damageDelt[index]);
         index -= 1;
     }
     timeInterval = 2.0f;
 }
 
               obviously the code for this could be cleaner and more according to your situation, but i think the logic of it is there. GL.
Answer by DubstepDragon · Feb 21, 2014 at 08:27 PM
A coroutine would simply be the best way. However, if you want to store items in list form, have a look at some basic arrays, they are same in Java/C# if I can recall correctly. But if you want it to be dynamic, at runtime, maybe you can use PlayerPrefs.
There are many ways to do it, depending on the way you think it through. It is best to know many and logically iterate through them depending on your flavor.
Please reply if you can/if I misunderstood something :D
Your answer
 
             Follow this Question
Related Questions
A node in a childnode? 1 Answer
List.Add component as Renderer, can't access? 1 Answer
Cant instantiate from one list to another? 2 Answers
Nested If Addition Going wrong somewhere? 1 Answer
Making a camera list 1 Answer