- Home /
Make a collider un-passable unless condition is met?
I want the end area of my game to be locked until the player has destroyed all the targets in the area. After they have did that then they can pass through the collider to the end game trigger to reach the end menu.
My problem is that I can't seem to figure out how to do this. I've set a variable to record the number of targets left in the scene. I don't know what to do after this.
Scripting done is in C# so if you post code then C# is preferable.
This is a project for uni.
Any help is appreciated, thanks ;)
Answer by nasa8 · Dec 05, 2013 at 07:30 PM
Say you have an un-passable game object called "block" with a collider component.
if (targetsLeft==0)
{
GameObject.Find("Block").GetComponent<Collider>().isTrigger = true;
}
and if it also has a ridgitbody component you'll have to make it kinematic:
if (targetsLeft==0)
{
GameObject.Find("Block").GetComponent<Collider>().isTrigger = true;
GameObject.Find("Block").GetComponent<Ridgitbody>().isKinematic = true;
}
Thank you so much. I spent ages trying to figure it out when it's so simple. I over complicate things as usual. It worked perfectly.
I was looking for that, didn't know where it was but I got it now.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Null reference that isn't null 2 Answers
If statment to check if player is within collider 1 Answer
How to make my game objects spawn when i walk through collider 3 Answers
How do I pull a script from a collider that my object is in? 1 Answer