Hi
I have lately been developing a platform game where you collect some glowing orbs however im having some trouble with my script.
The thing i want the script to do is:
After getting to a certain amount of points an orb turns on and when you touch that one you complete the level
The thing i just can’t get my script to do so.
Here is the code:
var score = 0;
var scoreText = “Score: 0”;
var mySkin : GUISkin;
function OnTriggerEnter( other : Collider ) {
Debug.Log(“OnTriggerEnter() was called”);
if (other.tag == “Glowball”) {
Debug.Log(“Other object is a glowball”);
score += 1;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString()); }
Since im not a scripter the code isnt mine. Its just a piece of code that i modified slighly to fit my needs.
But anyway… anyone who knows how to do this?
What do you mean by “orb turns on”? If you just want to load a new level after you collect a certain amount of points do this:
In the function OnTriggerEnter below the score += 1 add
if ( score >= 15) {Application.LoadLevel (“Level2”); }
Instead of Level2 put the name of the scene that you want to load, and instead of 15 add the number you want
What i mean by orb turns on is that a orb that has been off all through the level will turn on when the score hits a certain amount.
And then when you hit the orb you get a splash screen which tells you that you have completed the level and then you can go back to the level menu
you looks like want to do something like Neverball :
i’m with svl1002 but when you detect the player has passed the limit score, you activate the orbit object (you must previously disable before gamestarts) :
function Update(){
if (score >= 15){
ActivateOrb();
}
}
function ActivateOrb(){
var orb = GameObject.Find("orb");
orb.active = true;
}
then, in the orb, add a box collider and set it as a trigger and attach this script :
function OnTriggerEnter( other : Collider) {
YouWin();
}
function YouWin(){
//Show the win screen and results
yield WaitForSeconds(4); //So the player can see the results
Application.LoadLevel("level2");
}
Ok im having some trouble with the script :S
The orb isnt offline. It just stay online even tho i dont have the right amount of points.
What should i do?
Here is the code in question:
Orb Code:
function OnTriggerEnter( other : Collider) {
YouWin();
}
function YouWin(){
//Show the win screen and results
yield WaitForSeconds(2); //So the player can see the results
Application.LoadLevel(2);
}
Point System Code:
var score = 0;
var scoreText = “Score: 0”;
var mySkin : GUISkin;
var Orb = false;
function OnTriggerEnter( other : Collider ) {
Debug.Log(“OnTriggerEnter() was called”);
if (other.tag == “Glowball”) {
Debug.Log(“Other object is a glowball”);
score += 1;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
}
function Update(){
if (score >= 5){
ActivateOrb();
}
}
function ActivateOrb(){
var orb = GameObject.Find(“orb”);
Orb = true;
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString()); }
I cannot try now but I’m not sure that the Orb trigger isn’t fired when the gameobject is not active, also I would use a SendMessage to the Orb object for this instead of using a collider else you could try to check gameObject.active in the orb trigger
Im not sure i know what you’re saying :S
Can you elaborate it a bit?
Well, may be I misunderstood what is your problem. I don’t see in your latest scripts any code that deactivate (I think it should be in Start inside orb script) or activate the orb gameobject (it should be inside ActivateOrb after you Find “orb”). Also I don’t remember if OnTriggerEnter is fired even if its gameObject is not active so you should try (if it still is fired than of course you will add a check for gameObject.active inside OnTriggerEnter of the orb)
Ok so i played a little with the script and still can’t get it to work… The orb is still active even tho all the points (“Glowballs”) havent been collected yet :S
Can someone come with a example on what to do cause im really lost :S
I haven’t tried but imo it should be something like this:
orb:
function Start() {
gameObject.active = false;
}
function OnTriggerEnter( other : Collider) {
if (gameObject.active)
YouWin();
}
function YouWin(){
//Show the win screen and results
yield WaitForSeconds(2); //So the player can see the results
Application.LoadLevel(2);
}
points:
var score = 0;
var scoreText = "Score: 0";
var mySkin : GUISkin;
var Orb = false;
function OnTriggerEnter( other : Collider ) {
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Glowball") {
Debug.Log("Other object is a glowball");
score += 1;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
}
function Update(){
if (score >= 5){
ActivateOrb();
}
}
function ActivateOrb(){
var orb = GameObject.Find("orb");
if (orb != null) {
orb.active = true;
Orb = true;
}
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString());
}
Ok so i looked at the script and it removed the problem with the orb not being able to go unactive… however, now it cant get active again :S any ideas?
i found the error 
Under the “function ActivateOrb()” i deleted the var orb = GameObject.Find(“orb”) and instead i wrote a new variable at the top of the script 