Help Using Score to Load Level
HI All,
I have been trying to figure out how to use my current levels max score to load the next level using the below script.
There is no errors but it does not work once i reach the max level, any ideas?
using UnityEngine; using System.Collections;
public class AddPoints : MonoBehaviour {
public LevelManager levelManager;
public int Score=30;
// Use this for initialization
void Start () {
levelManager = FindObjectOfType<LevelManager>();
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.name == "Player")
{
levelManager.AddPoints(Score);
Destroy(this.gameObject);
}
if(Score >=780)
{
Application.LoadLevel(1);
}
}
}
Answer by ShadyProductions · Jan 24, 2016 at 10:02 PM
Maybe because you are never changing your Score int? :P
You mean like this? im still learning :)
public Level$$anonymous$$anager level$$anonymous$$anager;
public int Score=780; // Int Changed
// Use this for initialization
void Start () {
level$$anonymous$$anager = FindObjectOfType<Level$$anonymous$$anager>();
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.name == "Player")
{
level$$anonymous$$anager.AddPoints(Score);
Destroy(this.gameObject);
}
if(Score >=780)
{
Application.LoadLevel(1);
}
}
}
That would techniqually work, but it will add 780 all at once, if you want to trigger multiple objects that each add 30 points, you'll have to make a public int in your levelmanager and add 30 points to that int each time it triggers, and use that same int to check for 780 points in the trigger to load the next level.
I kinda just explained how you could do that.
You need to try something before you assume you cannot do it.
I can help if you can show me your AddPoints method of your level$$anonymous$$anager script.
You would need to do something like this:
Your level$$anonymous$$anager.AddPoints method, adds the score to a certain int.
You will have to use that int in the level$$anonymous$$anager. blabla to check it.
For example I am using totalScore, but it will be different in your level$$anonymous$$anager script.
if(level$$anonymous$$anager.totalScore >=780)
{
Application.LoadLevel(1);
}