- Home /
how can i load a scene when reaching certain score? Roll-a-Ball Project
Hello So i was watching the project roll a ball, instead of boxes i put coins and changed the game a little But in these videos it explains how to count score nothing about loading new scenes and stuff i fugured out by myself (wich is BIG thing) how to load a new scene i put a cube in the scene and a script like
using UnityEngine;
using System.Collections;
public class LevelLoad : MonoBehaviour {
void OnTriggerEnter(Collider other) {
Application.LoadLevel("Scene2");
}
}
but the score is "counted" or "Stored" in the character script It looks like this
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public GUIText countText;
public GUIText winText;
private int count;
void Start ()
{
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 7)
{
winText.text = "You May Now Pass To The Next Level!";
}
}
}
How i do to be Unable to pass to the next level unless you have "7" Score ?
and now that we are here i have another question How can i make menu's and stuff?
If anyone know's a link to documentation or tutorials for this things or any one knows to answer here
Thanx a lot :D
Answer by Digital-Phantom · Mar 24, 2015 at 01:41 PM
This tutorial will show you adding points / scores
http://unity3d.com/learn/tutorials/projects/space-shooter/counting-points
As for loading your next level at a certain score just a simple if statement will do that.
If(score >= 7) //in this case 'score' is just whatever variable name you allocate to your score system.
{
//Load your level here
}
quick reference to load level http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html
:)
thanks for the help
but i just got rid of the box and added in the playerController
[CODE]
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 7)
{
winText.text = "You $$anonymous$$ay Now Pass To The Next Level!";
Application.LoadLevel("Scene2");
}
[/CODE]
And now i have another problem when i get to score "count" 7 the level loads in a secound and it doesn't give time for the text to show the "winText.text" only show's for a secound or less...
just add an Invoke that loads the next scene in however many seconds you want.
thanks I $$anonymous$$ADE IT !!! this was the first step to make Fifa 16 Well i have the ball :D (that's important) :))
Answer by louis_k · Mar 26, 2015 at 07:36 AM
You may also use PlayerPrefs to save the score and retrieve it back
Good luck
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Application.LoadLevel ("lower") loads on start-up, not when triggered; Deadline is soon HELP! 3 Answers
Falldamage has no effect on my HB 2 Answers
OnTriggerEnter doesn't work 1 Answer