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 rapinnz · Jan 27, 2018 at 10:09 PM · scenescriptingbasicsscriptableobjectscreenshot

how can i test to see if there are more than one objects with a tag C#

I have 4 objects with a trigger when all four objects (fourth is out of the frame) alt text

i have a trigger around the cubes with this script.

 using UnityEngine;
 using System.Collections;
 
 public class ColorDetector : MonoBehaviour 
 {
     public GameObject Key;
 
     void OnTriggerEnter (Collider Keyz)
     {
         if (Keyz.gameObject.tag == "Yellow") 
         {
             if (Keyz.gameObject.tag == "Blue") 
             {
                 if (Keyz.gameObject.tag == "Red") 
                 {
                     if (Keyz.gameObject.tag == "Green") 
                     {
                         Debug.Log ("IT Worked");
                         Key.SetActive (true);
                     }
                 }
             }
         }    
     }
 }

and the script does not set the key to active. thanks to all who can help.

untitled.png (125.7 kB)
Comment
Add comment · Show 6
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 Commoble · Jan 27, 2018 at 10:13 PM 0
Share

Your script is testing if the one colliding object has all four tags on it, is that intentional?

avatar image rapinnz Commoble · Jan 27, 2018 at 10:17 PM 0
Share

no i want to test each cube individually and if all four are there the it sets the key to active

avatar image Commoble rapinnz · Jan 27, 2018 at 10:37 PM 0
Share

You'll need to check if the colliding object has any of the tags, then, not every tag. Then keep track of which objects have already collided with it.

Show more comments
avatar image jman12EX · Jan 27, 2018 at 11:29 PM 0
Share

This will work

 public bool havekeyBlue = false;
 public bool havekeyGreen = false;
 public bool havekeyRed = false;
 public bool havekeyYellow = false;
 public GameObject me;

 void Start()
 {

 }

 void Update()
 {

 }
 private void OnTriggerEnter(Collider collider)
 {
     if (collider.CompareTag("Blue$$anonymous$$ey"))
     {
         havekeyBlue= true;
     }

     if (collider.CompareTag("Green$$anonymous$$Ey"))
     {
         havekeyGreen = true;
     }
     if (collider.CompareTag("Red$$anonymous$$ey"))
     {
         havekeyRed = true;
     }
     if (collider.CompareTag("Yellow$$anonymous$$ey"))
     {
         havekeyYellow = true;
     }
 }
avatar image rapinnz jman12EX · Jan 28, 2018 at 12:09 AM 0
Share

thanks but i dont want the key to change color i want the trigger to detect that all four cubes are in the trigger then set the key to active.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SSEthanCray · Jan 28, 2018 at 03:54 AM

Is your debug.log coming out as "it worked"? If it isn't you could handle the code like this. I'm not sure if this is the type of answer you were looking for but here you go. using UnityEngine; using System.Collections;

  public class ColorDetector : MonoBehaviour 
  {
      public GameObject Key;
      private int colorCounter = 0;
 
      void Update() {
             if (colorCounter = 4) {
                    //setactive blah
 }
 }
  
      void OnTriggerEnter (Collider Keyz)
      {
             if (your thing is green) {
                    colorCounter++;
             }
              if (your thing is red) {
                    colorCounter++;
             }
              // repeat for your colors
       }
       void OnTriggerExit (Collider Keyz) 
       {
             if (your thing is green) {
                   colorCounter--;
             }
             if (your thing is red) {
                   colorCounter--;
             }
 //repeat for colors
 }
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

93 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

Related Questions

Accessing components via script and assigning randomized values to their parameters? 1 Answer

How to play to animations at same time ? 1 Answer

Scriptable Objects or Scenes ,Dungeon game: Use scens or Scriptable object? 0 Answers

Capture a (screen shot) scene shot with alpha 2 Answers

How do I make a photography function? 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