update text with foreach loop only renders last
Hi, I've noticed there are similar questions but I wasn't able to figure it out with none of them since I'm guessing it's something about the Object type and not the code. I guess this is very dumb, but I'm new at Unity, and at C#.
I have this simple foreach loop that goes through a list of tweets, and I want to render a Text with the first tweet of the list, wait a second, and then render the next one. The debug.Log shows the loop is working as expected, logging one tweet at a time, but the Text is only rendered with the last option of the list.
Can you explain to me what am I doing wrong?
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
public class Main : MonoBehaviour {
public GameObject Tweet;
public List<TweetSearchTwitterData> tweetList;
// Use this for initialization
void Start () {
TwitterAPI.instance.SearchTwitter("#anything", updateTweet);
}
void Update () {
}
void updateTweet(List<TweetSearchTwitterData> tweetList){
foreach(TweetSearchTwitterData t in tweetList) {
Debug.Log(t.tweetText);
string tweet = t.tweetText;
Tweet.GetComponent<Text>().text = tweet;
new WaitForSeconds(1);
}
}
}
Debug.Log:
Thank you!
Your answer
Follow this Question
Related Questions
UI Text created from C# Script 0 Answers
[HELP] To show wave number on a zombie survival game. 0 Answers
Text Objects do Lerp 0 Answers
How to do Ammo UI in Unity 5.3.4?,How to do Ammo UI in Unity 5 1 Answer
ui.text string matching doesn't work 0 Answers