Advertisement
Apidcloud

Collision with more than 1 object - hardcoded

Apr 5th, 2016
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. private bool _indexColliding = false;
  2. private bool _thumbColliding = false;
  3.  
  4. void OnCollisionEnter(Collision other) {
  5.     // keep track of the colliding objects
  6.     if (other.gameObject.tag == "index")
  7.         _indexColliding = true;
  8.     else if (other.gameObject.tag == "thumb")
  9.         _thumbColliding = true;
  10.  
  11.     if (_indexColliding && _thumbColliding) {
  12.         // do something like attaching the object to the fingers
  13.         // or destroy the gameObject
  14.     }
  15. }
  16.  
  17. void OnCollisionExit(Collision other) {
  18.     // reset the booleans if the objects are no longer colliding
  19.     if (other.gameObject.tag == "index")
  20.         _indexColliding = false;
  21.     else if (other.gameObject.tag == "thumb")
  22.         _thumbColliding = false;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement