SueNerdy Geschrieben 3. März 2019 Melden Share Geschrieben 3. März 2019 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 Zitieren Link zu diesem Kommentar Auf anderen Seiten teilen More sharing options...
Jomnitech Geschrieben 12. Mai 2019 Melden Share Geschrieben 12. Mai 2019 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?🙃 Zitieren Link zu diesem Kommentar Auf anderen Seiten teilen More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.