Answer the question
In order to leave comments, you need to log in
How to remove this thing through the code?
Hello! I'm making skins for the game and ran into the problem that the characters fall out again, and the question arose of how to remove the repetitions. I made the system itself with the help of a class (that is, I created a class in which I placed variables with a chance to drop out and on a character sprite) and I decided to simply remove this class from the list in the inspector, but I don’t know how to implement this through code.
Class
[System.Serializable]
public class Chance
{
public Sprite SpawnObject;
public int minSpawn = 0;
public int maxSpawn = 0;
}
Answer the question
In order to leave comments, you need to log in
In a script, you can use an ArrayList instead of an array, and remove an element using the RemoveAt (object index) method. You can also like this:
//Массив всех персонажей
[SerializeField] private GameObject[] characters;
//Метод для удаления персонажа из массива,
//в параметр передаем id персонажа-
private void DeleteCharacterFromArray(int id){
for(int i=id;i<characters.Length-1;i++){
characters[i]=characters[i+1];
}
Array.Resize(ref characters, characters.Length-1);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question