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 maroltl · Mar 23, 2014 at 07:26 PM · gameobjectenumaccesstype

Access objects enum type

Is there a way to detect enum type of object which my player collide with. I done lot of research, but I didnt find anything usefull.

Comment
Add comment · Show 2
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 getyour411 · Mar 23, 2014 at 07:35 PM 0
Share

An enum isn't something you collide with. Tell us more about what you are wanting to do.

avatar image maroltl · Mar 23, 2014 at 08:01 PM 0
Share

$$anonymous$$aybe I didnt explained it good enough. I have lot of blocks and i assign random enum type to them. When my player collide with one of them i want to get the enum type of that specific block(cube) .

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by getyour411 · Mar 23, 2014 at 09:26 PM

From your collision you'll get the cube/gameObject you collided with. From that you can do something like

 ScriptWithEnum scriptWithEnum = collision.gameObject.GetComponent<ScriptWithEnum>();

then you can do

 if(scriptWithEnum.variableOfTypeEnum.Enum.Value == "....") 
 // do stuff

Obviously change those values to ones that fit your code.

Comment
Add comment · Show 5 · 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 maroltl · Mar 23, 2014 at 09:29 PM 0
Share

Thanks for answer. I'll try it tomorrow since it is getting late here.

avatar image maroltl · Mar 25, 2014 at 05:54 PM 0
Share

var $$anonymous$$aterials; function OnCollisionEnter(col : Collision) { if(col.gameObject.name == "block(Clone)") { $$anonymous$$aterials = col.gameObject.GetComponent(materials); if($$anonymous$$aterials.BlockType.Enum.Value == "Dirt"){ Debug.Log("HitDirt"); } } } thats the code on which runs on collision. It gives $$anonymous$$e this error

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name) UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name) drilling+$OnCollisionEnter$3+$.$$anonymous$$oveNext () (at Assets/scripts/GameScripts/drilling.js:31)

materials is the script with enum in, and the Dirt is first type of enum.

avatar image getyour411 · Mar 26, 2014 at 10:55 PM 2
Share

Looks like a syntax error.

avatar image maroltl · Mar 27, 2014 at 06:47 AM 0
Share

Yea, but i dont know what what

avatar image maroltl · Mar 27, 2014 at 09:11 PM 0
Share

this code logs objects enum type to console.so the problem is not in accessing the enum type, since its working perfectly. problem is in comparing objects enum type (curType) with other enum values.

 function OnCollisionEnter(col : Collision)
     {
         if(col.gameObject.name == "block(Clone)")
         {   
                $$anonymous$$aterials = col.gameObject.GetComponent(materials);
                Debug.Log($$anonymous$$aterials.curType);
           }
 

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

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

Class hierarchy, gameObject, Raycast 1 Answer

Accessing other GameObjects Script Variables 2 Answers

Access main camera from different GameObject script 1 Answer

if statement inside variables of a class 1 Answer

Creating a Script at runtime, and adding it to an object... 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