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 yaezah · May 19, 2017 at 07:18 AM · ontriggerenteroncollisionenterontriggerexitontriggerstayoncollisionexit

How to make multiple gameobjects instantiate from one collider?

I'm trying to figure out what the best way to instantiate multiple game objects from one large collider

I tried attaching an invisible collider (is trigger) to my player and putting a bunch of gameobjects in front of him , what I'm trying to do is if he's looking in their direction the items would detect the player's invisible collider and instantiate a gameobject (which is a UI) right above them.

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

3 Replies

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

Answer by Ark_Revan · May 19, 2017 at 02:05 PM

What I would do is put a collider called "field of vision" attach to the player, and this collider would change a bool attach to each object which as an UI. If the bool is true, then the object display is UI, else , it hides it.

  function OnTriggerEnter (Collider other) {
      if(other.tag=="FieldOfVision") {
          bool = true;
          // or even directly UI.renderer.enable = true; if it works like this ( I don't use UI often^^")
      }
  }

And the opposite OnTriggerExit.

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 Ark_Revan · May 19, 2017 at 07:41 AM 0
Share

I forgot, the collider is (probably) some kind of triangle, and it is attach to an empty game object tagged with this new tag "FieldOfVision", then finally, you attach the object to the player( or his camera ).

All of this depends on the kind of game you want to do ( FPS / TPS / str ? )

avatar image yaezah Ark_Revan · May 20, 2017 at 01:42 AM 0
Share

Thanks for all the help. Just wonder, should I change other.tag to "Item" since that script above is going to be attached to player? Or is that script suppose to be attached to the Items?

avatar image Ark_Revan yaezah · May 20, 2017 at 04:45 PM 0
Share

No need to change other.tag.

If you create this FieldOfVision, then you check that the item "Enter the field of vision Collider". In order to check for this, you have to attach the script to the FieldOfVision object.

I just realized that the tag I wrote was a bad design choice. You should probably write something like : if ( other.tag =="ObjectWithUi") or whatever name you want. Sorry that the name I choose was misleading.

avatar image yaezah · May 19, 2017 at 04:43 PM 0
Share

Thanks , that sounds like it would work much better than my current way of trying to instantiate the UI via a script in the player. I will try it as soon as I get home. One thing though , when I add a trigger to the item's collider the item falls through the ground , it does have a rigidbody, so I'm not sure if I'm overlooking something simple or if I need to add a script.

avatar image archelyte_vz yaezah · May 19, 2017 at 04:48 PM 0
Share

Set the item's gravity scale to 0 in the rigidbody editor.

avatar image Ark_Revan yaezah · May 20, 2017 at 04:52 PM 1
Share

When a collider is set to "isTrigger", it lose his blocking ability.

What you should do is to let your first collider as it was, and create a new collider which "is trigger" and will help you create some "event" like "the player is looking".

You can put as many collider as you want to an object. But be careful to only have one which is responsible for collision. If there are more than one collider which doesn't have the IsTrigger option, then you will probably see some REALLY weird behaviour like the object suddenly flying in the air ( because he collide with himself so he's pushed ).

avatar image
1

Answer by shadowpuppet · May 19, 2017 at 01:40 PM

try it the other way around? put the trigger on the items with an void OnTriggerEnter (Collider other) { if(other.tag == "Player"){ script sow hen the player looks at them and his collider is in trigger zone UI element appears

Comment
Add comment · Show 1 · 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 yaezah · May 19, 2017 at 04:45 PM 0
Share

Thanks, will try that as soon as I get home ! One thing i remember happening though is my items would fall through the ground if I added is trigger to their collider even though they do have a rigidbody.. :(

avatar image
0

Answer by archelyte_vz · May 22, 2017 at 07:34 AM

Well if the objects are invisible until the player looks at them, then there are a few potential snags.

  1. If the objects are not already active in some way in the scene, it will very hard (if not impossible) for them to detect another object, because they are not active.

  2. If the objects are not already instantiated, they are likely not active either.

What may be a better solution is to have them already instantiated, active, and invisible (alpha at 0) at first. From there, when they detect the player change their alpha (1). That would look something like this (attached to the object, not the player):

void OnTriggerEnter (Collider trigger) { if (trigger.gameObject.tag == "Player") { StartCoroutine("DoFade"); } } IEnumerator DoFade() { Image uiImage= GetComponent<Image>(); while (uiImage.alpha < 1) { uiImage.alpha += Time.deltaTime; yield return null; } }

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.

Follow this Question

Answers Answers and Comments

69 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

Related Questions

How can I get trigger enter/exit every frame when I change Time.timeScale? 0 Answers

OntriggerEnter / Stay with the same Gameobject tags 0 Answers

How can I get my script to recognise when a collider exits while the box collider of the trigger object is disabled? 1 Answer

Can I access a script OnTrigger WITHOUT using getcomponent? 1 Answer

Have "OnTriggerStay" detection but only call it once? 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