Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Jan 26, 2015 at 07:10 PM by Ujean917 for the following reason:

Other

avatar image
1
Question by Ujean917 · Jan 26, 2015 at 06:01 PM · c#collidersstrings

error CS0019: Operator `==' cannot be applied to operands of type `UnityEngine.GameObject' and `string'

Hello, I am running into a wall here and I would like help. I have this empty parent game object that holds many children cube game objects that has colliders and another empty game object that has a collider of its own.

I want each of the respective children game object have their things called in the OnTriggerEnter because each children game object is supposed to cause an event in the game that I want it happen such as a dialogue box appearing.

However, it says I can't have strings to compare if two gameobjects have collided with eachother and I would like people's help if they could give me advise. Thanks in advance, I will continue to keep fiddling with this.

Here is the code I'm trying to work with:

 public class Wave0TutorialEventManager : MonoBehaviour 
 {
 
     public string collisionTagPlane = "PlayerPlane"; //The Player Plane Game Object
     private GameObject cameraGUI;  //The camera that will show all the text Boxes
     private GameObject wave0TutorialEvent1;
     private GameObject wave0TutorialEvent2;
 
     void Start()
     {
         cameraGUI = GameObject.FindGameObjectWithTag ("TextBoxCamera");
         wave0TutorialEvent1 = GameObject.Find ("Wave0TutorialEvent1");
         wave0TutorialEvent2 = GameObject.Find ("Wave0TutorialEvent2");
     }
 
     void OnTriggerEnter(Collider col)
     {
         if(wave0TutorialEvent1 == collisionTagPlane)
         {
             cameraGUI.SendMessage ("Wave0TutorialEvent1", true);
             Debug.Log ("Player Area has reached this point");
         }
 
         if(wave0TutorialEvent2 == collisionTagPlane)
         {
             cameraGUI.SendMessage ("Wave0TutorialEvent2", true);
             Debug.Log ("Player Area has reached second point");
         }    
     }
 }
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

  • Sort: 
avatar image
3
Best Answer

Answer by Anxo · Jan 26, 2015 at 06:49 PM

Replace

  if(wave0TutorialEvent1 == collisionTagPlane)

With

   if(wave0TutorialEvent1.name == collisionTagPlane)


b/c what you are doing is (GameObject is equal to String?) but what you want to do is (StringA is equal to StringB?)

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
3

Answer by meat5000 · Jan 26, 2015 at 06:06 PM

 wave0TutorialEvent1.name

Comment
Add comment · Show 2 · 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 Ujean917 · Jan 26, 2015 at 06:34 PM 0
Share

I'm assu$$anonymous$$g that should be placed in the comparison part of the if statements. I'll go try that now.

avatar image meat5000 ♦ · Jan 26, 2015 at 06:58 PM 0
Share

Indeed. It is how to access the actual String name of the GameObject, as seen in the inspector.

Note that String comparison is slow, but you won't have to worry about this most of the time.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

OnTriggerEnter() and OnTriggerExit() called multiple times despite checks. 3 Answers

Collision against conditions 1 Answer

Add Health on Pickup to Decaying Health,Make a collision with an object add health 2 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