• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by VoidUpdate · Apr 07, 2016 at 12:47 AM · c#unity 5collisionshaderhighlight

How to detect if an object is within another object??? (Hide and seek type game). Thanks!

alt text

alt text

Summary of whats already working and what is going on:

(IMAGE ONE) 1. A hider first selects a piece of furniture to hide their object in. When they submit, the object translates to the position of the furniture. When the object collides with the chosen furniture, the object gets hidden (disabled) inside the chosen furniture.

(IMAGE TWO) 2. The detectives (3 of them) take turns tapping (highlighting) furniture they think it is under. At the end of the turn, if the object is hidden under any of the highlighted furniture, the object is found (enabled).

   if (Input.GetMouseButtonDown(0))
         {
             
         //Send raycast to hit a game object
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         text.text = question;


         // Casts the ray and get the first game object hit
         if (Physics.Raycast (ray, out hit, Mathf.Infinity, layerToHit)) {

             lastClicked = hit.collider.gameObject.transform;
             clickedGameObject = hit.collider.gameObject;
             tapLastClicked = hit.collider.gameObject.transform;


//THIS IS FOR THE HIDER SELECTING AND SENDING OBJECT TO DESIRED FURNITURE

             if (hit.collider.tag == "Object" && lastClicked != null && spawned == false && sessionCounter == 0 && taptaptapSelect.enabled == false) {
                 //Debug.Log ("This hit at " + hit.transform.name);
                 print (lastClicked.name);
                 objectSelect.enabled = true;
                 objectIsHere = lastClicked;
                 moveOn = false;

//THIS IS FOR THE FIRST DETECTIVE HIIGHLIGHTING A SPECIFIC FURNITURE

             } else if (hit.collider.tag == "Object" && lastClicked != null && taptaptapSelect.enabled == true ) {
                 //Debug.Log ("This hit at " + hit.transform.name);
                 rend = clickedGameObject.GetComponent<Renderer> ();
                 tapOneOriginalMaterial = rend.material;
                 //tapOne = lastClicked.gameObject;
                 print (clickedGameObject.gameObject.name );
                 print ("Tap One");
                 //tapCounter += 1;
                 tapOneBool = true;
                 rend.material = diffuseShaderPlayerOne;


//What is the best method to detect when the object is under one of the highlighted furniture? I've tried many different methods and no luck so far. All my code is working, other than this system I'm trying to get going. I'd appreciate all the help

imageone.png (421.8 kB)
imagetwo.png (428.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by JigneshKoradiya · Apr 07, 2016 at 06:05 AM

i can give some idea about how you can do it

first you have two object object-A and Object-B

you have to use boxcollider and make check box ON "is trigger" from inspector and than refer to this script

http://docs.unity3d.com/ScriptReference/Collider.OnTriggerStay.html

here is you can check if Object-A is in Object-B than you can get event in OntriggerStay method

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by saschandroid · Apr 07, 2016 at 06:45 AM

You could probably use something like this on your objects:

 if( GetComponent<MeshFilter>().mesh.bounds.Contains(/* position of the hidden object*/))
 {
      Debug.Log("Bounding box contains hidden object!");
  }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Button Enabling/Disabling using Collision Triggers? 1 Answer

My rigidbody2d is passing through the side of a collider2d but it's working on the top 0 Answers

How can i look for collisions of the bulidngs in may array ? how can i use OnTRiggerEnter/exit ? 0 Answers

How to access a prefab's boolean property through collision (with the same Prefab but different Instance)? 1 Answer

How can i disable or enable particle effects on a child object when the parent object collides with something? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges