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 /
  • Help Room /
avatar image
0
Question by Quetz00 · Feb 12, 2018 at 06:32 AM · functionif-statementsenum

How can I use an "Enum e" I passed from another script in an If or Switch Statement

Good evening. I am trying to make a set of buttons that disable/enable an object in my card game; Every Card has an enum type called rarity, and an Instance of it called currentCR that I manually set to BRONZE For test purposes. So I created the following Function:

     public void DisableVaultCard(GameObject vault, Enum e)
     {     
         for(int i =0; i < vault.transform.childCount; i++)
         {
             //CardProperties is a script in every Card.
             if(e == vault.transform.GetChild(i).GetComponent<CardProperties>().currentCR)
             {
 
             }
         }
     }

and It is being called from this Script:

 public class DisableEnableCard : MonoBehaviour, IPointerClickHandler
 {
     public Image image;
     public Sprite[] buttonState;
     bool pressed = false;
 
     private GameObject vault;
     private CardGUILogic cardGUILogic = new CardGUILogic();
 
     void Awake()
     {
         image = GetComponent<Image>();
         vault = GameObject.Find("/DeckBuilderHolder/Card Picker Panel/Scroll View/Viewport/Content");
     }
 
     public void OnPointerClick(PointerEventData eventData)
     {
         pressed = !pressed;
 
         if(pressed)
         {
             image.sprite = buttonState[1];
             **cardGUILogic.DisableVaultCard(vault, CardProperties.rarity.BRONZE);**
         }
         else
         {
             image.sprite = buttonState[0];
             **cardGUILogic.EnableVaultCard(vault, CardProperties.rarity.BRONZE);**
         }
 
     }
 }

It would be much apreciated if someone told me how to make the if statement work. The Debug.Log(e) Displays the value BRONZE so I do not know what I am Missing.

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 ShadyProductions · Feb 12, 2018 at 07:47 AM 1
Share

There is nothing wrong with the code as far as I can see, Put a debug inside the if statement:

 Debug.Log("E: " + e + " CurrentCR: " + currentCR);

And see if they are the same.

avatar image Quetz00 ShadyProductions · Feb 14, 2018 at 12:42 AM 0
Share

It had to do with my hierarchy as I Had each card inside a panel for Disable/Enable purposes without disabling the cards scripts.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Quetz00 · Feb 12, 2018 at 07:44 AM

I solved it already. I had to use e.Equals(vault.transform.GetChild(i).GetComponentInChildren().currentCR)

and it solved it. Thanks to everyone anyway. And also hope that this helps someone else.

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

75 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

Related Questions

Is this bug known? function parameter s and if statements c# 1 Answer

Null Reference with ifstatements accessing enum types. 2 Answers

Enumaration error CS1025: Single-line comment or end-of-line expected 1 Answer

How to check to see if Switch Case is true. 1 Answer

How do I run an animation then destroy 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