- Home /
Question by
KieranG · May 17, 2013 at 12:33 AM ·
c#charactercontroller
How would I use this to check if the player has a key and is touching a door?
Not sure how to use this.
Thanks
Comment
Wiki
Answer by randomuser · May 17, 2013 at 12:41 AM
This example can be implemented very simply.
Add OnControllerColliderHit(ControllerColliderHit hit){} to your code and it will be called whenever something collides with the script. Add this to your door and and the tag "Key" to your lock. Then you can go
OnControllerColliderHit(ControllerColliderHit hit){
if( gameObject.tag == "Key") {
//Code for door hit here
return;
}
else {
return;
}
}
Didn't work. Also, what Im looking more for is something like:
if(something.tag == "Door" && Have$$anonymous$$ey == true){
Destroy(something.gameObject);
}
if (hit.collider.tag == "Door" && have$$anonymous$$ey == true)
Destroy(hit.collider.gameObject);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
C# CharacterController.SimpleMove Goes on Forever 1 Answer
Using GUI skin with my GUI Button 1 Answer
How to insert an if statement for Selection Grid C# 1 Answer
Weird GUILayout Scrollview Behavior 0 Answers