Y
Y
Yura Mailler2021-02-26 07:35:30
Unity
Yura Mailler, 2021-02-26 07:35:30

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;
    }

60387a88c7805218085690.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Black Basher, 2021-02-26
@BlackBasher

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 question

Ask a Question

731 491 924 answers to any question