Jump to content
Unity Insider Forum

Adi_321

Newbie
  • Posts

    3
  • Joined

  • Last visited

Adi_321's Achievements

Newbie

Newbie (1/3)

0

Reputation

  1. Das funktioniert, dann taucht jedoch dieser Fehler auf: Assets\Scripts\Spowner.cs(26,46): error CS0103: The name 'pipe' does not exist in the current context Code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spowner : MonoBehaviour { public float maxtime = 1; private float timer = 0; public GameObject[] pipes; public float height; // Start is called before the first frame update void Start() { var index = Random.Range(0, pipes.Length); var pipe = pipes[index]; GameObject newpipe = Instantiate(pipe); newpipe.transform.position = transform.position + new Vector3(0, 0, 0); } // Update is called once per frame void Update() { if(timer > maxtime) { GameObject newpipe = Instantiate(pipe); newpipe.transform.position = transform.position + new Vector3(0,0,0); Destroy(newpipe, 15); timer = 0; } timer += Time.deltaTime; } }
  2. Vielen Danke für die schnelle Antwort. Ich habe soweit alles abgeändert. Jetzt bekomme ich aber diesen Fehler: Assets\Scripts\Spowner.cs(17,30): error CS0311: The type 'UnityEngine.GameObject[]' cannot be used as type parameter 'T' in the generic type or method 'Object.Instantiate<T>(T)'. There is no implicit reference conversion from 'UnityEngine.GameObject[]' to 'UnityEngine.Object'. Bei der Zeile 26 bekomme ich genau den gleichen. Mein Code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spowner : MonoBehaviour { public float maxtime = 1; private float timer = 0; public GameObject[] pipes; public float height; // Start is called before the first frame update void Start() { var index = Random.Range(0, pipes.Length); var pipe = pipes[index]; GameObject newpipe = Instantiate(pipes); newpipe.transform.position = transform.position + new Vector3(0, 0, 0); } // Update is called once per frame void Update() { if(timer > maxtime) { GameObject newpipe = Instantiate(pipes); newpipe.transform.position = transform.position + new Vector3(0,0,0); Destroy(newpipe, 15); timer = 0; } timer += Time.deltaTime; } } An was liegt das?
  3. Hi Ich erstelle zurzeit ein Unity Spiel. In diesem habe ich ca 10 verschiedene Pipes. Ich möchte das zufällig eine dieser Pipes ausgewählt wird und eingefügt wird. Hier mein Code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spowner : MonoBehaviour { public float maxtime = 1; private float timer = 0; public GameObject pipe; public float height; // Start is called before the first frame update void Start() { GameObject newpipe = Instantiate(pipe); newpipe.transform.position = transform.position + new Vector3(0, 0, 0); } // Update is called once per frame void Update() { if(timer > maxtime) { GameObject newpipe = Instantiate(pipe); newpipe.transform.position = transform.position + new Vector3(0,0,0); Destroy(newpipe, 15); timer = 0; } timer += Time.deltaTime; } } Bis jetzt wurde einfach immer die Pipe 1 eingefügt, Vielen Dank Adrian
×
×
  • Create New...