What I am trying to do is make pressing Z on the keyboard toggle between 3 values. I cannot figure out how I would do this.
So:
value is 1 > Z is pressed > value toggles to 2 > Z is pressed > value toggles to 3 > Z is pressed > value toggles back to 1
z = (z % 3) + 1;
and don’t forget to make it 1; at default
check the time difference between the first and next button . you can solve it easily … Time.deltaTime use this…
Griffo
3
Try this, but I don’t think Fattie will like it (else if) … 
#pragma strict
private var onePress : boolean = true;
private var twoPress : boolean = false;
private var threePress : boolean = false;
function Start () {
}
function Update () {
if (Input.GetKeyDown ("z")){
keyPress();
}
}
function keyPress(){
if (onePress && !twoPress && !threePress){
onePress = false;
twoPress = true;
threePress = false;
// Do Stuff
print("Button press 1");
}else if (!onePress && twoPress && !threePress){
onePress = false;
twoPress = false;
threePress = true;
// Do Stuff
print("Button press 2");
}else if (!onePress && !twoPress && threePress){
onePress = true;
twoPress = false;
threePress = false;
// Do Stuff
print("Button press 3");
}
}
using UnityEngine;
using System.Collections;
public class first : MonoBehaviour {
private int z = 1;
void Update () {
if (Input.GetKeyDown(KeyCode.Z))
{
z = (z % 3) + 1;
print (z);
}
}
}
I found out why it stops at 1…
The code:
z = (z % 3) +1;
It only works 3 times. If I set it to 5 it works 5 times. If I set it to 57 it works 57 times.
How do I make it go between 1-3 forever?