I have tried to add the proper comments so that it is understandable, but I may have over-complicated it. This is something I have been using to practice making menus in case you’re wondering why someone would make a game where you look at letters. I noticed that it was going to be different than anything I have done in unity, so I wanted to keep it separate from my other things in my project until i figured it out. Basically, this script moves a selector around to different choices, ranging from A-I. Moving up and left are working properly, but when you try to move down or right, it registers the controls like its a GetKey() and goes to the end of the row or column. I will include a picture of the menu to help it make more sense. Any help is greatly appreciated! If anyone has any questions, please ask and i will do my best to explain.
#pragma strict
private var A : int;
private var B : int;
private var C : int;
private var D : int;
private var E : int; //These variables keep track of what option the player is currenly on
private var F : int;
private var G : int;
private var H : int;
private var I : int;
private var back : int;
function Start () { //The selector starts on selecion A
transform.position.x = -5.98;
transform.position.y = 2.63;
A = 1;
B = 0;
C = 0;
D = 0;
E = 0;
F = 0;
G = 0;
H = 0;
I = 0;
back = 0;
}
function Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
if (D == 1) { //The Selector is on D
transform.position.x = -5.98; //Moves selecter to A
transform.position.y = 2.63;
D = 0; //Selector is no longer on D
A = 1; //Selector is now on A
Debug.Log ("A");
}
if (E == 1) {
transform.position.x = 0; //Moves selecter to E
transform.position.y = 2.63;
E = 0; //Selector is no longer on E
B = 1; //Selector is now on B
Debug.Log ("B");
}
if (F == 1) {
transform.position.x = 5.95; //Moves selector to F
transform.position.y = 2.63;
F = 0; //Selector is no longer on E
C = 1; //Selector is now on C
Debug.Log ("C");
}
if (G == 1) {
transform.position.x = -5.93; //Moves Selector to G
transform.position.y = -0.33;
G = 0; //Selector is no longer on G
D = 1; //Selector is now on D
Debug.Log ("D");
}
if (H == 1) {
transform.position.x = 0; //Moves Selector to H
transform.position.y = -0.38;
H = 0; //Selector is no longer on H
E = 1; //Selector is now on E
Debug.Log ("E");
}
if (I == 1) {
transform.position.x = 6; //Moves Selector to I
transform.position.y = -0.38;
I = 0; //Selector is no longer on I
F = 1; //Selector is now on F
Debug.Log ("I");
}
if (back == 1) {
transform.position.x = 0; //Moves Selector to back
transform.position.y = -3.2;
back = 0; //Selector is no longer on back
H = 1; //Selector is now on H
Debug.Log ("H");
}
}
if (Input.GetKeyDown(KeyCode.DownArrow)) {
if (A == 1) {
transform.position.x = -5.93; //Moves Selector to A
transform.position.y = -0.33;
A = 0; //Selector is no longer on A
D = 1; //Selector is now on D
Debug.Log ("D");
}
if (B == 1) {
transform.position.x = 0; //Moves Selector to B
transform.position.y = -0.38;
B = 0; //Selector is no longer on B
E = 1; //Selector is now on E
Debug.Log ("E");
}
if (C == 1) {
transform.position.x = 6; //Moves Selector to C
transform.position.y = -0.38;
C = 0; //Selector is no longer on C
F = 1; //Selector is now on F
Debug.Log ("F");
}
if (D == 1) {
transform.position.x = -6; //Moves Selector to D
transform.position.y = -3.29;
D = 0; //Selector is no longer on D
G = 1; //Selector is now on G
Debug.Log ("G");
}
if (E == 1) {
transform.position.x = 0; //Moves Selector to E
transform.position.y = -3.2;
E = 0; //Selector is no longer on E
H = 1; //Selector is now on H
Debug.Log ("H");
}
if (F == 1) {
transform.position.x = 6; //Moves Selector to F
transform.position.y = -3.39;
F = 0; //Selector is no longer on F
I = 1; //Selector is now on I
Debug.Log ("I");
}
if (G == 1) {
transform.position.x = 0; //Moves Selector to G
transform.position.y = -5.45;
G = 0; //Selector is no longer on G
back = 1; //Selector is now on back
Debug.Log ("back");
}
if (H == 1) {
transform.position.x = 0; //Moves Selector to H
transform.position.y = -5.45;
H = 0; //Selector is no longer on H
back = 1; //Selector is now on back
Debug.Log ("back");
}
if (I == 1) {
transform.position.x = 0; //Moves Selector to I
transform.position.y = -5.45;
I = 0; //Selector is no longer on I
back = 1; //Selector is now on back
Debug.Log ("back");
}
}
if (Input.GetKeyDown(KeyCode.RightArrow)) {
if (A == 1) {
transform.position.x = 0; //Moves Selector to A
transform.position.y = 2.63;
A = 0; //Selector is no longer on A
B = 1; //Selector is now on B
Debug.Log ("B");
}
if (B == 1) {
transform.position.x = 6; //Moves Selector to B
transform.position.y = 2.63;
B = 0; //Selector is no longer on B
C = 1; //Selector is now on C
Debug.Log ("C");
}
if (D == 1) {
transform.position.x = 0; //Moves Selector to D
transform.position.y = -0.38;
D = 0; //Selector is no longer on D
E = 1; //Selector is now on E
Debug.Log ("E");
}
if (E == 1) {
transform.position.x = 6; //Moves Selector to E
transform.position.y = -0.38;
E = 0; //Selector is no longer on E
F = 1; //Selector is now on F
Debug.Log ("F");
}
if (G == 1) {
transform.position.x = 0; //Moves Selector to G
transform.position.y = -3.2;
G = 0; //Selector is no longer on G
H = 1; //Selector is now on H
Debug.Log ("G");
}
if (H == 1) {
transform.position.x = 6; //Moves Selector to H
transform.position.y = -3.29;
H = 0; //Selector is no longer on H
I = 1; //Selector is now on I
Debug.Log ("I");
}
}
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
if (B == 1) {
transform.position.x = -5.98; //Moves Selector to B
transform.position.y = 2.63;
B = 0; //Selector is no longer on B
A = 1; //Selector is now on A
Debug.Log ("A");
}
if (C == 1) {
transform.position.x = 0; //Moves Selector to C
transform.position.y = 2.63;
C = 0; //Selector is no longer on C
B = 1; //Selector is now on B
Debug.Log ("B");
}
if (E == 1) {
transform.position.x = -5.93; //Moves Selector to E
transform.position.y = -0.33;
E = 0; //Selector is no longer on E
D = 1; //Selector is now on D
Debug.Log ("D");
}
if (F == 1) {
transform.position.x = 0; //Moves Selector to F
transform.position.y = -0.38;
F = 0; //Selector is no longer on F
E = 1; //Selector is now on E
Debug.Log ("E");
}
if (H == 1) {
transform.position.x = -6; //Moves Selecter to H
transform.position.y = -3.2;
H = 0; //Selector is no longer on H
G = 1; //Selector is now on G
Debug.Log ("G");
}
if (I == 1) {
transform.position.x = 0; //Moves Selector to I
transform.position.y = -3.2;
I = 0; //Selector is no longer on I
H = 1; //Selector is now on H
Debug.Log ("H");
}
}
}