Hello guys, I was wondering if you guys could help me out. It’s the last thing that needs to happen and then I’m sure to win a prize with this thing at school!
Okay, so here is the problem. I have a first person perspective game, where people need to run through a level as fast as they can. They need to visit certain key points (“cyrstals”) before the level is finished. I was going to do this by having them collide with these crystals.
I have 7 crystals through the level.
How do I make it so that it registers the collision between the object, destroys the light effect of it so that you can see you’ve seen it already, and register how much you’ve collided as well?
Add a script to your crystal that deals with physics trigger detection. You will need to have a collider on each crystal (a BoxCollider or a SphereCollider should do the job).
Example of script:
void OnTriggerEnter( Collider other )
{
// test to make sure the player hit the trigger
// for example:
if(other.gameObject.name == "Player")
{
// call a method on the player to increment a counter
other.gameObject.GetComponent<PlayerScript>().PlusOne();
// destroy the crystal
Destroy( this.gameObject );
// or disable light
DisableLight();
// and remove collider
Destroy(GetComponent<Collider>());
}
}
Almost the same in Js.
Add this one to your crystal ball prefab, I would guess the lighting system is childed:
Crystal.js
static var count: int = 7;
var pling :AudioClip;
function OnTriggerEnter(other:Collider){
if(other.gameObject.tag =="Player"){
count -=1;
AudioSource.PlayAtPoint(pling,transform.position);
Destroy(gameObject);
}
on your player or level ground or any object that will remain
function Update(){
if(Crystal.count == 0)
{
Application.LoadLevel("WinningScreen");
}
}