Jump to content
Unity Insider Forum

Hilfe: Objekte willkürlich respawnen lassen


SueNerdy

Recommended Posts

Hallo Community,

ich bräuchte eure Hilfe.

Und zwar hab ich eine Spieler-Figur und zahlreiche Objekte, die fallen. Nun hab ich es hinbekommen, dass die Objekte gezählt werden und veschwinden.

Nur wie lass ich sie willkürlich respawnen?

 

Das Script sieht folgendermaßen aus:

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Coin : MonoBehaviour
{
    private int coinCounter;
    public Text scoreText;

    // Start is called before the first frame update
    void Start()
    {
        coinCounter = 0;
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if(other.tag == "Coin")
        {
            coinCounter++;
            Destroy(other.gameObject);
            scoreText.text = "Score: " + coinCounter.ToString();
            Debug.Log("Score: "+coinCounter);
        }
    }
}

 

 

Kann mir bitte jemand helfen?

Grüße

SueNerdy

 

Link zu diesem Kommentar
Auf anderen Seiten teilen

  • 2 months later...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Coin : MonoBehaviour
{
    private int coinCounter;
    public Text scoreText;

    public float randomX;
    public float randomY;

    // Start is called before the first frame update
    void Start()
    {
        coinCounter = 0;


        transform.position = new Vector2(Random.Range(-randomX, randomX),Random.Range(-randomY,randomY));
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Coin")
        {
            coinCounter++;
            Destroy(other.gameObject);
            scoreText.text = "Score: " + coinCounter.ToString();
            Debug.Log("Score: " + coinCounter);
        }
    }
}

So vielleicht? Ist deine Frage überhaupt noch aktuell?🙃

Link zu diesem Kommentar
Auf anderen Seiten teilen

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Auf dieses Thema antworten...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Lädt...
×
×
  • Neu erstellen...