Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by skeptika · Feb 20, 2014 at 01:00 AM · list

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:

  1. Record the damage produced by the match to a List (this I can do);

  2. Have it show the damage output above the character in a scrolling/combat style (this I can also do);

  3. 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;
     }
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Feb 20, 2014 at 06:11 AM 0
Share

You could adapt my answer here which has spacing time: http://answers.unity3d.com/questions/258368/who-killed-who-scrolling-gui-text.html

avatar image skeptika · Feb 21, 2014 at 08:21 PM 0
Share

Thanks this worked! Thanks to the other replies as well, all helpful.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges