Drag input:
//when using mouse
Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
// get the current position of the player GameObject
Vector3 originalPos = this.transform.position;
// replace the x coordinate with the x of touched pos.
originalPos.x = touchPos.x;
// set the player position to the modified one
this.transform.position = originalPos;
Adding a highscore:
public int score;
public int highscore;
//retrieve highscore
highscore = PlayerPrefs.GetInt("High Score");
//set new highscore
if(score > highscore){
highscore = score;
PlayerPrefs.SetInt("High Score", highscore);
}
Adding a restart button:
if(GUI.Button(new Rect((Screen.width / 2) - 160,(Screen.height / 2) - 40, 320, 80), "Again?")) {
Application.LoadLevel(0);
}
I also learnt more about controlling the font size, text allignment etc. through modifying skins:

No comments:
Post a Comment