- Home /
Add points when player passes through something + Timer
Before we start, let me just put this out there. I started using Unity yesterday, and know little to none coding. With that said, here is the problem.
I have a car game with a bunch of ramps and stuff.
I want to have rings of some sort floating, after the ramps, so you can jump through them and earn points.
I also want a timer, so if you don't score the required points to pass a level, you go to a loose scene. If you score enough points, you go to the win scene.
I have no idea of how to even start to go about this.
Thanks in advance.
Answer by Statement · Mar 24, 2011 at 06:54 PM
You can make use of Invoke to create a lose timer. You can make use of OnTriggerEnter to add score and check for win conditions. You can make use of tags to check if the trigger is a "Ring" tagged trigger.
This script could be placed on your car but you probably want to change the Win and Lose functions.
var score = 0; var goal = 10; var timeLimit = 30;
Invoke("Lose", timeLimit);
function Lose() { enabled = false;
// Load scene or do any other losing presentation.
Application.LoadLevel("LoseScene");
}
function Win() { CancelInvoke("Lose"); enabled = false;
// Load scene or do any other winning presentation.
Application.LoadLevel("WinScene");
}
function OnTriggerEnter(other : Collider) { // If you have no other triggers, // you can ignore the tag check.
if (!enabled || other.tag != "Ring")
return;
if (++score >= goal)
Win();
}
Your answer
Follow this Question
Related Questions
The timer starts after a collision with an object 1 Answer
How to set lap timer for network multiplayer 0 Answers
Script for Car 2 Answers
How to add waypoints/ timers for a car game! 1 Answer
advanced countdown timer help please 0 Answers