Hello I dont really have a lot of experience with List so I need some help
When i hit enemy, He register the name who hit him the last and i have a basic GlobalKillcount script with list on it
List
List
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Annoucer : MonoBehaviour {
public List<AnnoucerData> Data = new List<AnnoucerData>();
}
using UnityEngine;
using System.Collections;
public class AnnoucerData : MonoBehaviour {
public string Name;
public int Kills;
}
what i need to write in to the death function to check if the list contains the player name and if it doesnt create one section in list and add one kill or if it already exists in the list just add one kill to it.
Health script
using UnityEngine;
using System.Collections;
public class Health : MonoBehaviour {
public int HealthPoints;
public string LastHitBy;
// Update is called once per frame
void ApplyDamage (int Damage) {
HealthPoints -= Damage;
if (HealthPoints <= 0) {
Death();
}
}
void Death() {
Destroy (gameObject);
}
}
Oh sorry, I was on hurry
Let me sort this out,
What I want to do Is to register Player kills to the list.
So what I’ve done by now is only register who killed the enemy, but what I need to know Is how can I send this information to my List, how to check If that player have killed anyone in the past, If he did, just add one kill in to hes data, If not, create a new section for him and so on…
I’m guessing it’s because you’re using a List instead of a Dictionary<string, int>?
If you really want to use the AnnouncerData class (it’s just a wrapper around a data pair, so not really very usefull), you’ll have to create a new instance of that class, set the name and kill count, and add it to the list.