Touchbased Difficulty Select menu defaults to Hard (Integer 2)

I’m currently in progress of making a small Casual mobile game. I’ve got the main parts sorted for it, apart from the “Difficulty Select Menu”.

For some reason the script below doesn’t seem to follow the logic of it and loops 2 or 3 times unless you select the “Hard” button. This is the pattern I’ve noticed from it:

Easy Selected → Goes straight to Hard.
Medium Selected → Loops to Easy → and again to Hard.
Hard Select → It works…

Below is what the code looks like:

using UnityEngine;
using System.Collections;

public class Diff_Select : MonoBehaviour {

	public int difficultyItem; // 0 = Easy, 1 = Medium and 2 = Hard

	public GameObject menuObject;

	public Vector3 endPosition = new Vector3(-40.0f,0.0f,0.0f);

	public bool isMoving = false;
	public bool isGetReady = false;

	public float transTime = 0.5f;

	public float currentTimes = 0.0f;
	public float countDownWait = 1.0f;
	public int countDown = 5;
	public TextMesh countDownText;
	public int currentDiff;

	public bool selected = false;
	// Use this for initialization
	void Start () {
		PlayerPrefs.SetInt ("DiffSelect",0);
	// Update is called once per frame
	void Update () {
		if(isMoving == true && isGetReady == false){
		if(menuObject.transform.position.x <= -39.5f && isGetReady == false){
			selected = true;
			isGetReady = true;

		if(isGetReady == true && selected == true){
			currentTimes += Time.deltaTime;
			countDownText.text = countDown.ToString ("0");
			if(currentTimes >= countDownWait){
				currentTimes = 0.0f;
				if(countDown <= 0 && isGetReady == true){
					//Load the next level
					Debug.Log ("Diff Item = " + difficultyItem + ", countDown = " + countDown + ", GameObject Name: " +;

					PlayerPrefs.SetInt ("DiffSelect",difficultyItem);
					//currentDiff = PlayerPrefs.GetInt ("DiffSelect");
					//Debug.Log ("Current Diff = " + currentDiff);
					if(difficultyItem == 0){
						PlayerPrefs.SetFloat ("WaitTime",60.0f);

						Application.LoadLevel (1);
					if(difficultyItem == 1){
						PlayerPrefs.SetFloat ("WaitTime",40.0f);
						Application.LoadLevel (1);
					if(difficultyItem == 2){
						PlayerPrefs.SetFloat ("WaitTime",20.0f);
						Application.LoadLevel (1);


	//Message Sent from the Input Manager
	void OnTouchOver(){
		isMoving = true;

	//Small Function to Lerp the Menu.
	void LerpMenu(Transform transObject,Vector3 startPos, Vector3 endPos, float time){
		float i = 0.0f;
		float rate = 1.0f/time;
			i += Time.deltaTime * rate;
			transObject.position = Vector3.Lerp (startPos, endPos, i);

Now the code above logically should Set the PlayerPrefs and then load the next level. But it doesn’t seem to and I can’t see where I might be going from

If you see anything I’m missing or have suggestions on alternative methods feel free to throw them at me. Your help is very much appreciated.

Many Thanks,


Update on the situation:

I’ve got back today after having a weekend away from Game Development, and I got it immediatly.

Basically where I had the script attached to multiple Game Objects it looped through the same script ending on the Hard button.

To solve this I moved the PlayerPrefs.SetInt("DiffSelect",difficultyItem); to the end of the void OnTouchOver() function. So rather than the difficulty being set in the time system, it got set when the button is pressed. Which isn’t shared between all the game objects.

I hope this makes sense to anyone reading this.