I’m trying to have it switch between 2 maps with the push of a button it goes one way but not the other.
#pragma strict
var old : byte ;
function Start () {
old = 0;
}
function Update () {
if (Input.GetKeyDown ("r")) {
if (old == 1){
transform.Translate(Vector3.left * 1000, Space.World);
old = 0;
}
if (old == 0){
transform.Translate(Vector3.right * 1000, Space.World);
old = 1;
}
}
};
First of all Unity never supported
(https://en.wikipedia.org/wiki/Java_(programming_language)). Unity supports **Unityscript**, a language implementing the [ECMA specification](https://en.wikipedia.org/wiki/ECMAScript), making it similar to **Javascript**.
Here is the correct script
#pragma strict
var old : byte ;
function Start()
{
old = 0;
}
function Update()
{
if ( Input.GetKeyDown( "r" ) )
{
if ( old == 1 )
{
transform.Translate( Vector3.left * 1000, Space.World );
old = 0;
}
else if ( old == 0 ) // The else here is important
{
transform.Translate( Vector3.right * 1000, Space.World );
old = 1;
}
}
}