Detecting an object inside a trigger
So i want to check if a door is locked depending on if there is a lock infront of it or not. the door has a trigger area for where the lock is but my question is how do i detect the lock in code? I think it should be a OnTriggerStay since it will be unlocked when the lock is destroyed.
Describe your problem in more details, maybe even post some pictures. What you´re describing can be done in many ways, but it might not suit needs of your game.
Answer by $$anonymous$$ · Nov 07, 2016 at 01:44 PM
well i want to detect if a certain gameobject (the lock) is within the trigger zone of another gameobject (the door). imgur.com/a/bCyuM ok i made a simplified version of the scenario. If you beat the first block the second blocks lock is destroyed. i want to detect if the lock is in the trigger zone and if it isn't it will do something. I know there might be a better way of detecting if the level is beat but i want to try this version. I don't really know what else to add. I just want to know what line of code would work for this.
Answer by Zynek · Nov 07, 2016 at 07:45 PM
Well if you need the lock as a separate object, you have to add rigidbody and collider to it, so it triggers the event. But what i would personally do, is to make the lock part of the Door prefab, give the door script boolean "locked" and on changes of this variable i would enable/disable the lock in hiearchy, so it hides when unlocked.
Your answer
Follow this Question
Related Questions
How to detect collision of two moving characters? 1 Answer
Coroutine being called multiple times from trigger. 1 Answer
Finding contact point in OnTriggerEnter2D? 0 Answers
Enemy Trigger Colliders are triggering my player's trigger collider. Why? 1 Answer
move pooled object on collision/trigger but keep pooling it 1 Answer