Hello,
currently I try to make a little “inventory script”.
If I press the “F” button, the game stops and 4 “buttons” appear and around the first button a cursor.
If the D button is pressed the cursor shall move 1 button to the right
and if A is pressed one button to the left.
But somehow if I press D, it jumps from button number 1 to button number 4.
But backwards it works perfectly 4-3-2-1.
So my question is… why does the cursor jumps from 1 to 4 ? ^^;
using UnityEngine;
using System.Collections;
public class InventoryController : MonoBehaviour {
//Item Anzeigen
public Texture item1;
public Texture item2;
public Texture item3;
public Texture item4;
//Ausgewählte Items
public Texture auswahl1;
public Texture auswahl2;
public Texture cursor;
private bool inventarAn;
private float cursorLocation;
void Start (){
cursorLocation = 1.1f;
}
void Update ()
{
if (Input.GetKeyDown ("f")) {
Debug.Log ("F gedrückt !");
if (inventarAn == false) {
Time.timeScale = 0;
inventarAn = true;
} else {
inventarAn = false;
cursorLocation = 1.1f;
Time.timeScale = 1;
Debug.Log ("F aus !");
}
}
if (inventarAn == true) {
if (cursorLocation == 1.1f) {
if (Input.GetKeyDown ("d")) {
cursorLocation = 1.2f;
Debug.Log ("1.2");
}
}
if (cursorLocation == 1.2f) {
if (Input.GetKeyDown ("d")) {
cursorLocation = 1.3f;
Debug.Log ("1.3");
}
if (Input.GetKeyDown ("a")) {
cursorLocation = 1.1f;
Debug.Log ("1.1");
}
}
if (cursorLocation == 1.3f) {
if (Input.GetKeyDown ("a")) {
cursorLocation = 1.2f;
Debug.Log ("1.2");
}
if (Input.GetKeyDown ("d")) {
cursorLocation = 1.4f;
Debug.Log ("1.4");
}
}
if (cursorLocation == 1.4f) {
if (Input.GetKeyDown ("a")) {
cursorLocation = 1.3f;
Debug.Log ("1.3");
}
}
}
}
void OnGUI ()
{
if (inventarAn == true) {
// Inventar Grafiken werden ausgegeben
GUI.DrawTexture (new Rect (20, 20, 100, 100), item1, ScaleMode.ScaleToFit);
GUI.DrawTexture (new Rect (120, 20, 100, 100), item2, ScaleMode.ScaleToFit);
GUI.DrawTexture (new Rect (220, 20, 100, 100), item3, ScaleMode.ScaleToFit);
GUI.DrawTexture (new Rect (320, 20, 100, 100), item4, ScaleMode.ScaleToFit);
//Cursor Grafik
if (cursorLocation == 1.1f) {
GUI.DrawTexture (new Rect (20, 20, 100, 100), cursor, ScaleMode.ScaleToFit);
}
if (cursorLocation == 1.2f) {
GUI.DrawTexture (new Rect (120, 20, 100, 100), cursor, ScaleMode.ScaleToFit);
}
if (cursorLocation == 1.3f) {
GUI.DrawTexture (new Rect (220, 20, 100, 100), cursor, ScaleMode.ScaleToFit);
}
if (cursorLocation == 1.4f) {
GUI.DrawTexture (new Rect (320, 20, 100, 100), cursor, ScaleMode.ScaleToFit);
}
}
}
}