A better way to do it
I'm using unity to make a game. I have multiple animal enemies in the game.
I'm working on missions inside the game that you have to kill a random number of random animals, this i already have.
What i have a problem with is to increase the mission count when you kill an animal.
I got a script (dead) sitting on each animal, when the animal dies it calls a public function inside the dead script.
from the dead script it should increase an int value in the "MissionHolder" script where all the animals have a int value to increase when you kill a animal.
The problem is i don't know which animal gets killed when the player kills a animal, what i did is this...:`
public string Name;
public MissionHolder missionHolder;
public void Kill()
{
if (name == "Tiger")
{
missionHolder.Tiger += 1;
}
if (name == "Hyena")
{
missionHolder.Hyena += 1;
}
if (name == "Gorilla")
{
missionHolder.Gorilla += 1;
}
if (name == "Giraffe")
{
missionHolder.Giraffe += 1;
}
if (name == "Gazelle")
{
missionHolder.Gazelle += 1;
}
etc.
Now i just name each animal by it's name on the dead script but this is not really efficient.
Does anyone knows a better way to do this?
Well I am having a bit of trouble here. So everything works? All you want is a better way to do it. Well maybe you can classify a list of strings that you reference from. $$anonymous$$ake a class where you classify an animal by the gameObject and then a string in which will be it’s name. Such as referencing the game object of the tiger and classifying the string as tiger and every time you kill that game object you know it’s a tiger.
Your answer
Follow this Question
Related Questions
.Exe gets slower over time 0 Answers
Cross-Scene Simulation? 0 Answers
FPS drop beacause Dialog with 200 images in it 0 Answers
AMD RYZEN 1800X or Intel i7 7700K? 2 Answers
Should you instantiate new particle systems or keep them active inside gameobjects? 2 Answers