- Home /
How can i destroy a collider on collision?
I was wondering if anyone could help me out with this little problem. Basically I want the player to be able to roll into an object (the player is a sphere shaped object) and get points for hitting the object, but I don't want the player to keep getting points if they roll into it after the first time.
Is there a script I can make to say destroy the collider on the object or is there a much better way of doing this?
Also I'm very new to scripting and I was wondering if anyone could also help tell me how to make a point system in the game and have the score appear on the screen.
Thanks guys!
You've asked two separate questions, both of which have been asked countless times before. Please take a moment to search the existing questions (individually) before posting a new question - cheers!
$$anonymous$$y apologies if it has been asked before, but I've spent ages searching for it and I never found anyone else asking this particular question.
No one seems to be asking how to keep an object physics based so it bounces away and you also get points for it.
And I was searching for exactly this so I applaud him for posting here.
Answer by flaviusxvii · Apr 28, 2011 at 02:31 PM
The problem here is that you've loaded your question with physics/collision/destroy stuff when you REALLY just wanted a way to only count collisions once.
You can do with with a simple boolean variable. Set it to true if it's false and count it. Ignore it otherwise.
Answer by Joshua · Apr 28, 2011 at 01:44 PM
Give all the objects you want to be destroyable the same tag, for instance "Destroy". Add the follow script (or into an existing script) on the player.
function OnCollisionEnter (hit : Collision) {
if(hit.gameObject.tag == "Destroy") {
Destroy(hit.gameObject);
}
}
Thanks for the reply. The only problem with this is I don't want the objects to disappear into thin air, I want the objects to bounce away physics based, but I don't want the player to be able to score points from it if it has already been hit :)