I have scoring to add one point each time one object collides with another, and you lose a life after you collide with an object your not supposed to collide with. When I run out of lives the game ends as its supposed to.
But I want to set it up so that when player reaches a certain score the game stops also.
I have a GUI Text set up to show player what their goal is
But for each level the goal is different.
EXAMPLE:
Score: 12
Goal: Score 25 (GUI Text)
I know how to set it up to be the same goal everytime, but I want different goals.
Not sure where to start with this
This is my Player Script, attatchment is at bottom
using UnityEngine;
using System.Collections;
public class Game10_Player : MonoBehaviour
{
public GUISkin skin; //GUI Skin
public int score; //Score
public int lives; //Lives
private Vector3 pos; //Position
private bool dead; //If we are dead
void start ()
{
//Set screen orientation to landscape
Screen.orientation = ScreenOrientation.Landscape;
//Set sleep timeout to never
Screen.sleepTimeout = SleepTimeout.NeverSleep;
}
void Update ()
{
//If dead
if (dead)
{
//Set collider to false
collider.enabled = false;
return;
}
//If we have 0 lives left
if (lives < 1)
{
//Kill
dead = true;
//Set collider to false
collider.enabled = false;
}
//If the game is running on a android device
if (Application.platform == RuntimePlatform.Android)
{
//If we are hitting the screen
if (Input.touchCount == 1)
{
//Find screen touch position
pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, 1));
//Set position
transform.position = new Vector3(pos.x,pos.y,0);
//Set collider to true
collider.enabled = true;
return;
}
//Set collider to false
collider.enabled = false;
}
//If the game is not running on a android device
else
{
//Find mouse position
pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
//Set position
transform.position = new Vector3(pos.x,pos.y,0);
}
}
void OnTriggerEnter(Collider other)
{
//If we hits a fruit
if (other.tag == "Fruit")
{
//Run hit function
other.GetComponent<Game10_Fruit>().Hit();
//Add score
score += 1;
}
//If we hits a enemy (bomb)
else if (other.tag == "Enemy")
{
//Run hit function
other.GetComponent<Game10_Bomb>().Hit();
}
}
void OnGUI()
{
GUI.skin = skin;
//Score
GUI.Label(new Rect(10,10,300,300),score.ToString());
//If dead
if (dead)
{
//Show "Lives: 0"
GUI.Label(new Rect(10,Screen.height - 35,300,300),"Lives: 0");
}
else
{
//Show lives left
GUI.Label(new Rect(10,Screen.height - 35,300,300),"Lives: " + lives.ToString());
}
//If dead
if (dead)
Application.LoadLevel("YouLose");
}
}1221924–50531–$Game10_Player.cs (2.21 KB)