I am working on a project that displays a sprite from a folder with country images, where the user has to guess the country. Once I have selected a random sprite, I want to be able to remove that sprite from the list. However, I have been trying multiple methods which have not worked so far. I have tried.remove, .removeAt and.destroy and I still get the same error as shown below:
'Sprite' does not contain a definition for 'destroy' and no accessible extension method 'destroy' accepting a first argument of type 'Sprite' could be found (are you missing a using directive or an assembly reference?
public class quizManager : MonoBehaviour
{
[SerializeField] Sprite [] countryImages;
[SerializeField] SpriteRenderer spriteRenderer;
int randomNumber;
public string correntCountry;
void Start()
{
countryAppear();
}
public void countryAppear(){
randomNumber = Random.Range(1, countryImages.Length);
spriteRenderer.sprite = countryImages[randomNumber];
countryImages.Remove(randomNumber);
currentCountry = countryImages[randomNumber].ToString().Split(' ')[0];
Debug.Log(currentCountry.Split(' ')[0]);
}
}
You can try to use List<Sprite>
instead of Sprite[]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.