- Home /
How to reset a level by collecting items?!?!
Hello, i need a script for when i collect a collectable object but when you collect all the object it resets the level. thanks!
Answer by Psychlade · Oct 21, 2011 at 07:52 AM
No one here is going to write up a script for you, but we can push you in the right direction. ;)
First, if you don't know how to do something so basic, I think you should get acquainted with the tutorials all over the internet. I'm on them everyday and just can't help myself. It's that fun once you get past the first few 'pits' of scripting. Not hard at all, just fun.
If your collecting gameObjects, let's say 10, I would assign a trigger to each of the them. This trigger would add 1 point to an integer variable and when you've collected all 10 gameObjects, you can do what was suggested in the selected answer here.
Here's the link for a good starting point for Triggers. Have fun!
Answer by ocularcash · Oct 21, 2011 at 08:10 AM
you really should learn to write code. It's alot easier to get help from ppl if you type what you understand and someone can just adjust it. but this is an easy script so i'll give you a simple code. There's a bunch of different ways to do this but the main ways are to make the objects inactive (invisible) which you can turn back on at any given time, like if you have to get it from the same point more than once, or call a destroy function which takes the object completely out. Coding is very easy to understand. How you would say it is pretty much how you write it.
var CollectedObjects : int = 0;
var Coin1 : GameObject;
var Coin2 : GameObject;
function Update()
{
if(CollectedObjects >= 2)
{
Application.LoadLevel(1);
CollectedObjects -= 2;
}
}
function OnControllerColliderHit (hit : ControllerColliderHit)
{
if(hit.gameObject.tag == ("coin1"))
{
CollectedObjects += 1;
Coin1.active = false;
}
if(hit.gameObject.tag == ("coin2"))
{
CollectedObjects += 1;
Coin2.active = false;
}
}
Good answer, wasted by bad formatting. Seriously, just press the 10101 button after selecting your code! I just did that, btw.
Answer by Aydan · Oct 21, 2011 at 09:08 AM
var neededCollectable : int = 5;
var amountCollected : int = 0;
function Start(){
amountCollected = 0;
}
function Update(){
if(amountCollected == neededCollectable){
Application.LoadLevel(0);
}
}
function OnTriggerEnter(collision : Collider){
if(collision.gameObject.tag == ("Collectable")){
amountCollected += 1;
}
}
This should do it just add a tag called "Collectable" to your collectables, set the collectables collider to is trigger and set the neededCollectable variable to however many collectables you need to pass the level. Hope it helps.
Your answer
Follow this Question
Related Questions
"Reset Level", Application.LoadLevel 1 Answer
How to Reset Scene after Level Completion 1 Answer
reset the level? 5 Answers
How can I reset my level when the player walks on a specific floor in the game? 2 Answers
reset level on collision 3 Answers