- Home /
Multiplying a feed after kill
I have a score feed, which displays a text that says "15+" when ever i kill an enemy, but the problem is, if i shoot multiple enemies in a small time range it will just show "15+" throughout it, so it would be hard to distinguish between each kill. I want it to double whenever i get multiple kills within a certain time range (i know it says multiply in the title, but it looks better.). Here is an example from CoD: https://www.youtube.com/watch?v=aU8OKGlYpfk
I've searched it up, but i still can't find a good solution, i've been pondering for a while now.
XP feed code, that pops up a text (saying 15+) whenever i kill someone:
public class XpFeed : MonoBehaviour {
public float showtime;
Text text;
public int xpFeed;
void Awake()
{
// Set up the reference.
text = GetComponent<Text>();
// Reset the score.
}
void Update()
{
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "+" + xpFeed + "xp";
}
public void getFeed()
{
StopCoroutine("showfeed");
text.enabled = true;
StartCoroutine("showfeed");
}
public IEnumerator showfeed()
{
yield return new WaitForSeconds(showtime);
text.enabled = false;
}
}
And enemy AI code:
public class AIHealth : MonoBehaviour
{
public int xpValue = 15;
public GameObject xpfeed;
void Awake()
{
xpfeed = GameObject.Find("XPFeed");
}
void Death()
{
XPManager.curXp += xpValue;
xpfeed.GetComponent<XpFeed>().getFeed();
}
}
Then ins$$anonymous$$d of using only 1 permanent text object, you can make a text prefab. After you killed an enemy, spawn that text prefab (make it fall down in 1~2s then destroy it).
If you only want to use 1 text object, then after you killed an enemy, enable that text and make zoom effect, if you kill another target in a short time then just instantly resize it to original size then zoom it again.
Answer by ForeignGod · Jan 18, 2017 at 09:20 AM
Make a timer.
Each time you get a kill set timer at 3sec or something.
Check if timer is more than 0 and if it is add 15 to your xpfeed variable.
If timer is 0 do your regular code.
Answer by KarenCrawford · Jan 18, 2017 at 09:11 AM
You can check youtube for ´scrolling combat text tutorial´ and do a similar solution to that if you are having a lot of messages incoming.
In my game, it was much slower and I could never have more than 2 messages at a time, so I did an easier solution. I had two text boxes, Primary and Secondary with primary slightly below secondary.
then I did
If ( primary is active in hierarchy)
put text in secondary
else
put text in primary.
I guess that could work, i'll give it a shot and see if i like it :) Thank you :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612104902im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I add used Time in scoreboard 0 Answers
Loading a score on a scene 2 Answers
Score and Level Loading 1 Answer
Get score in areas 0 Answers