Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question destroying targets sequentially

Discussion in '2D' started by abdullaharslantas0, Apr 6, 2021.

  1. abdullaharslantas0

    abdullaharslantas0

    Joined:
    Mar 15, 2021
    Posts:
    4
    Merhaba. Ben yeniyim. Rastgele oluşturduğum sayıları (sayılar gamobject, resim olarak geliyorlar ekrana) bir görüntü olarak yok etmek istiyorum. Ama sırayla yok edemiyorum, 1,2,3,4,5 gibi sırayla yok etmeliyim ve sıra dışı bas başladığında oyunun yeniden başlaması veya bitmesi gerekiyor. Lütfen bir kod örneği paylaşıp bana sırayla onu yok etmeyi öğretir misin?
     
    Last edited: Apr 6, 2021
    JackHolman likes this.
  2. JackHolman

    JackHolman

    Joined:
    Jun 28, 2019
    Posts:
    9
    I am going to write a response in English and run it through google translate to Turkish for you in case you don't know English. All code has not been tested.

    İngilizce bilmiyorsanız sizin için İngilizce bir cevap yazacağım ve google translate'den Türkçe'ye çevireceğim. Kodun tamamı test edilmemiştir.

    I am assuming that you want to have a number of object destroy in your scene in a particular order with a particular delay. This is not too difficult to do in Unity.

    Sahnenizde belirli bir sırayla belirli bir gecikmeyle bir dizi nesnenin yok edilmesini istediğinizi varsayıyorum. Bunu Unity'de yapmak çok zor değil.

    Firstly you are going to want a list of your objects in order, see code below:

    Öncelikle, sırayla nesnelerinizin bir listesini isteyeceksiniz, aşağıdaki koda bakın:

    Code (CSharp):
    1. public List<GameObject> objectList;
    Then, you are going to want a counting variable:

    Ardından, bir sayma değişkeni isteyeceksiniz:

    Code (CSharp):
    1. private int index = 0;
    Now you are going to create a function that will destroy your object:

    Şimdi nesnenizi yok edecek bir işlev yaratacaksınız:

    Code (CSharp):
    1. private void DestroyObject() {
    2.     if (index < objectList.size) {
    3.         Destroy(objectList[index]);
    4.     }
    5.     else {
    6.         CancelInvoke();
    7.     }
    8. }
    Finally, you are going to want to invoke your method to repeat:

    Son olarak, tekrarlamak için yönteminizi çağırmak isteyeceksiniz:

    Code (CSharp):
    1. InvokeRepeating("DestroyObject", 0f, **repeat delay**);
    In this case **repeat delay** is the amount of time you want to have between each call of the destroy method.

    Bu durumda **repeat delay**, yok etme yönteminin her çağrısı arasında olmasını istediğiniz süredir.

    This probably isn't the most efficient way of doing this but should get your system working.

    Bu muhtemelen bunu yapmanın en verimli yolu değildir, ancak sisteminizin çalışmasını sağlamalıdır.
     
    abdullaharslantas0 and MelvMay like this.
  3. abdullaharslantas0

    abdullaharslantas0

    Joined:
    Mar 15, 2021
    Posts:
    4
    Thank you very much, my friend. You are the only answer. I am grateful. But I want to do it in order of numbers, not that way. I'll take a sample picture.
     
  4. abdullaharslantas0

    abdullaharslantas0

    Joined:
    Mar 15, 2021
    Posts:
    4
  5. abdullaharslantas0

    abdullaharslantas0

    Joined:
    Mar 15, 2021
    Posts:
    4
    Gördüğünüz gibi en küçüğünden başlayarak bu sayıları tek tek elemek istiyorum ama sıraya koyamıyorum. Ortadan kaybolurlar ama kontrol edilmezler.