Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 dasilvamarcok · Dec 22, 2019 at 10:12 AM · collidertriggervrtagsnewbie

VR : How to check if object held passed through trigger Zone

Hey there, I'm quite new to unity and i'm trying to learn the ropes for VR game development.

Is there a way to make it so the object detected in the collision is the object i'm holding and not myself ?

I'm trying to create a trigger zone that when i enter it with a specific object in my hand in spawns something.

For now my trigger zone spawns something each time i pass through, and i'm trying to use tags to correct that, without much success, has my collider is always my hand and not the object i'm holding... Do you have any idea on how to correct that ?

here's my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SpawnBottle : MonoBehaviour
 {
     // Start is called before the first frame update
     public Transform Spawnpoint;
     public GameObject Prefab;
     public bool EnteredTrigger;
     public GameObject m_bottle;
 
     void Start(){
         //m_bottle = GameObject.FindGameObjectWithTag("Bottle");
     }
     void update() {
         if(EnteredTrigger){
             Instantiate(Prefab, Spawnpoint.position, Spawnpoint.rotation);
         }
     }
 
     void OnTriggerEnter(Collider other){
         if(other.name == "Bottle"){
             Debug.Log ("Bottle is here");
         }else{
             Debug.Log ("Bottle is not here");
         }
         if(other.gameObject.CompareTag("Bottle")){
             EnteredTrigger= true;
         }
         
     }
 }

Thanks a lot

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by cgklutts · Dec 22, 2019 at 11:37 AM

Could you not just put the collider on the game object you are carrying? If not.. you could put a bool on the player and trigger toggle it on and off if you are carrying that item.. and use logic that way within the collsion..

Comment
Add comment · Show 6 · 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 dasilvamarcok · Dec 22, 2019 at 12:38 PM 0
Share

Hey thanks for the answer!

that's where i'm butting my head on, when i specify in the ONtriggerEnter method the collider i use, it picks the collider of my hand, and i don't know how to access "m_bottle" box collider to use it to trigger the function.

i wanted to use use the tag of the gameobject i have but it doesn't seem to work.

avatar image cgklutts dasilvamarcok · Dec 22, 2019 at 01:15 PM 0
Share

So when you play this game the console prints out "Bottle is not here" correct?

avatar image cgklutts dasilvamarcok · Dec 22, 2019 at 01:26 PM 1
Share

You shouldn't need //m_bottle = GameObject.FindGameObjectWithTag("Bottle"); This code at all. If you are carrying a game object that has a collider and a rigid body attatched to it.. and both are set to trigger it should pick up the collision within the OnTriggerEnter..

avatar image cgklutts cgklutts · Dec 22, 2019 at 01:28 PM 1
Share

after you Instantiate the game object you are going to need to set EnteredTrigger to false or you are going to spawn a zillion of them.

Show more comments

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.

Follow this Question

Answers Answers and Comments

201 People are following this question.

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

Related Questions

Ball activating triggers even with a script 0 Answers

Weird behaviour with OnTriggerEnter 0 Answers

Can't click gameobject when over another trigger? 1 Answer

My script isn't detecting OnTriggerEnter why? 1 Answer

Undefind tag? 0 Answers


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