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 /
avatar image
0
Question by el_kloklo · Dec 22, 2012 at 12:29 PM · c#gameobjecttype

C# : comparison of type between gameobject of specific type

Hello all,

First I thank you for all the other questions and answer you already have done, because it helped me a lot for most of my problems. It's really nice to have all this help stored here, and it's avoid me to ask questions which have already been answered.

I have a question, and possibly it has been replied somewhere, but I didn't find it. My problem is the following : I am trying to test the type of an object, and it's always returning true. The code is following :

 using UnityEngine;
 using System.Collections;
 
 public class TileScript : MonoBehaviour {
     
     private GameObject TileContent;
 
 [...]

 public void TileAffectObject(GameObject objectassigned)
 {
     this.TileContent=objectassigned;
     objectassigned.transform.localPosition = new Vector3(this.transform.localPosition.x,0,this.transform.localPosition.z);
 }

 public bool TileIsFree()
 {
     if(    this.TileContent == null)
         return true;
     else
         return false;
 }

 
     public bool TileContentIs(GameObject comparison)
     {
         if(TileIsFree())
             return false;
         if(TileContent.GetType() == comparison.GetType())
             return true;
         return false;
     }
 }
 

I think this because the comparison is between two GamObject, and that's probably where I am wrong, but for example one is an empty object with a script A, and the other is a cube with a script B, and I want to be able to store both of them in the object TileScript.

Thanks for your time.

el_kloklo

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

Answer by paulaceccon · Dec 26, 2012 at 11:43 PM

Yeah, what is happening is what you've said before. Both are game objects, so the comparison always return true. I didn't understand how do you would like this to behave. Did you think about using tags and maybe compare the objects' tags?

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 Bunny83 · Dec 26, 2012 at 11:53 PM

A GameObject is just a container. There are no other types that are derived from GameObject. The GameObject class can't even be derived. Your classes are derived from MonoBehaviour which is a Component. Components are attached to GameObjects. We don't know how your game setup looks like, so it's hard to tell what this code should actually do.

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 el_kloklo · Dec 27, 2012 at 10:18 PM

Hello, thanks for your answers and merry christmas.

I am searching a way for comparing two objects which are contained as a gameobject. Maybe the tag could be a solution, but I don't know how it's work.

Another solution I am currently looking in is making the TileContent stored as myclass which return a static string identifiant, and all the object I want to store in derivate from the class myclass, and overload the identifiant, but I have problem with overloading static method.

I don't know if I am clear, but maybe a schematics could help a bit :

alt text

Thanks for your time


inherit equal.png (15.9 kB)
inherit equal.png (16.4 kB)
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

11 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

gameObject are not referenced 2 Answers

Ordering a list of GameObjects 3 Answers

How to scroll progressively a game object? 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