Hey everybody,
I’m working on a game that is similar to Ninjump, where a single tap will make the player jump from one side of the screen to the other. While I’m waiting for art, I’m just using a Cube for the player and walls. I’m not really sure what the best way to make this happen is, and was hoping that you guys could help.
I have my left wall at -4, right wall at 4, and the player at -3. During the game, a hit of the spacebar will move the player directly across the game play area on the same Y value, but on the opposite wall.
Here is my current jump method, which crashes on start up (it is called by a Director object, which takes care of all user input. It calls this method upon hit of the spacebar):
public class onJump : MonoBehaviour {
bool isRight = false; //true if player is on right wall, false otherwise
bool canJump = true;
public void Bounce(){
if (isRight && canJump) {
Debug.Log ("Move left!");
transform.Translate(new Vector3(this.transform.position.x - 6, 0, 0) * Time.deltaTime);
} else if(!isRight && canJump) {
Debug.Log ("Move right!");
transform.Translate(new Vector3(this.transform.position.x + 6, 0, 0) * Time.deltaTime);
}
//isRight = !isRight;
StartCoroutine (timer());
}
IEnumerator timer(){
canJump = false;
yield return new WaitForSeconds (2);
canJump = true;
}
}
Thank you for the help ![]()