Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
//gekürzt: using UnityEngine; using System.Collections; public class sSpieler : MonoBehaviour { public GameObject oerSchwert; void Update () { if (Input.GetKeyDown (KeyCode.Space)) { GameObject schwertpawn = (GameObject)Instantiate(oerSchwert, new Vector3(0,2,0), transform.rotation); } } } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
//vollständig: using UnityEngine; using System.Collections; public class sSpieler : MonoBehaviour { // Use this for initialization void Start () { newPosition = this.transform.position; direction = 1; InBewegung = false; } Vector3 newPosition; byte direction; bool InBewegung; public GameObject oerSchwert; //public Transform spawnPoint; // Update is called once per frame void Update () { newPosition = this.transform.position; if (Input.GetKeyDown (KeyCode.Space)) { //GameObject _schwert = (GameObject) //Instantiate(oerSchwert, new Vector3(0,0,0),Quaternion.identity); GameObject schwertpawn = (GameObject)Instantiate(oerSchwert, new Vector3(0,2,0), transform.rotation); } if (Input.GetKey (KeyCode.W)) { direction = 1; InBewegung = true; } if (Input.GetKey (KeyCode.S)) { direction = 3; InBewegung = true; } if (Input.GetKey (KeyCode.A)) { direction = 4; InBewegung = true; } if (Input.GetKey (KeyCode.D)) { direction = 2; InBewegung = true; } if (InBewegung) { if (direction == 1) { newPosition.y += 0.1f; } if (direction == 3) { newPosition.y -= 0.1f; } if (direction == 4) { newPosition.x -= 0.1f; } if (direction == 2) { newPosition.x += 0.1f; } } this.transform.position = newPosition; InBewegung = false; } } |
Zitat
The variable oerSchwert of sSpieler has not been assigned. You probably need to assign the oerSchwert variable of the sSpieler script in the inspector.
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Neuinstallation hat noch nie Compile-Fehler gefixt.Entweder übersehe ich irgendetwas oder ich muss Unity neuinstallieren.
C#-Quelltext |
|
1 2 |
[SerializeField]
private GameObject schwertPrefab;
|
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Werbeanzeige