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 /
This question was closed Jul 05, 2017 at 08:18 PM by tanoshimi for the following reason:

http://answers.unity3d.com/questions/1374267/operator-cannot-be-applied-to-operands.html?childToView=1374276#comment-1374276

avatar image
0
Question by RobertOne · Jul 05, 2017 at 07:46 PM · enumoperator

cannot be applied to operands

Hey! so i got this script:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 
 namespace HB.Snowboarding
 {
 
 public class NewBehaviourScript : MonoBehaviour {
 
     private PhysicsCharacterState m_ghostPhysicsCharacterState;
     private float m_railBoardPressThreshold;
     private float m_boardPressThreshold;
         private bool m_useSwitchControls;
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
         public PhysicsCharacterState CharacterState
         {
             get
             {
                 return this.CharacterState;
             }
         }
 
         private void SetTurnBehavior(float inputAngle, Quadrant initialQuadrant)
         {
             bool onRail = this.CharacterState.onRail;
             float num = (!onRail) ? this.m_boardPressThreshold : this.m_railBoardPressThreshold;
             if (initialQuadrant == null || initialQuadrant == 3)
             {
                 if (inputAngle < num || inputAngle > 360f - num)
                 {
                     this.CharacterState.turnBehavior = ((!this.m_useSwitchControls) ? TurnBehavior.NosePress : TurnBehavior.TailPress);
                 }
                 else
                 {
                     this.CharacterState.turnBehavior = TurnBehavior.Carve;
                 }
             }
             else if (initialQuadrant == 1 || initialQuadrant == 2)
             {
                 if (inputAngle > 180f - num && inputAngle < 180f + num)
                 {
                     this.CharacterState.turnBehavior = ((!this.m_useSwitchControls) ? TurnBehavior.TailPress : TurnBehavior.NosePress);
                 }
                 else
                 {
                     this.CharacterState.turnBehavior = TurnBehavior.Carve;
                 }
             }
             else
             {
                 this.CharacterState.turnBehavior = TurnBehavior.Carve;
             }
         }
 
     }
 }
 

which is giving me the following error:
error CS0019: Operator ==' cannot be applied to operands of type Quadrant' and `int'

the Quadrant gets calculated like this:

 public static Quadrant GetQuadrant(Vector2 v)
     {
         v = v.normalized;
         float angle = Utilities.Normalize360(Mathf.Atan2(v.y, v.x) * 57.29578f);
         return Utilities.GetQuadrant(angle);
     }
 
     public static Quadrant GetQuadrant(float angle)
     {
         Quadrant result = Quadrant.None;
         angle = Utilities.Normalize360(angle);
         if (angle <= 90f)
         {
             result = Quadrant.I;
         }
         else if (angle <= 180f)
         {
             result = Quadrant.II;
         }
         else if (angle <= 270f)
         {
             result = Quadrant.III;
         }
         else if (angle <= 360f)
         {
             result = Quadrant.IV;
         }
         else
         {
             UnityEngine.Debug.LogWarning("Undefined Quadrant!");
         }
         return result;
     }

and has this enums:

 using System;
 
 public enum Quadrant
 {
     None = -1,
     I,
     II,
     III,
     IV
 }
 

when i write the first script like this:

 private void SetTurnBehavior(float inputAngle, Quadrant initialQuadrant)
         {
             bool onRail = this.CharacterState.onRail;
             float num = (!onRail) ? this.m_boardPressThreshold : this.m_railBoardPressThreshold;
             if (initialQuadrant == Quadrant.None || initialQuadrant == Quadrant.III)
             {
                 if (inputAngle < num || inputAngle > 360f - num)
                 {
                     this.CharacterState.turnBehavior = ((!this.m_useSwitchControls) ? TurnBehavior.NosePress : TurnBehavior.TailPress);
                 }
                 else
                 {
                     this.CharacterState.turnBehavior = TurnBehavior.Carve;
                 }
             }
             else if (initialQuadrant == Quadrant.I || initialQuadrant == Quadrant.II)
             {
                 if (inputAngle > 180f - num && inputAngle < 180f + num)
                 {
                     this.CharacterState.turnBehavior = ((!this.m_useSwitchControls) ? TurnBehavior.TailPress : TurnBehavior.NosePress);
                 }
                 else
                 {
                     this.CharacterState.turnBehavior = TurnBehavior.Carve;
                 }
             }
             else
             {
                 this.CharacterState.turnBehavior = TurnBehavior.Carve;
             }
         }

everything is fine. but out of convenience i would like to keep the "initialQuadrant == 3" instead of "initialQuadrant == Quadrant.III"

does anyone of you have a solution for this?

Comment
Add comment · Show 1
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 RobAnthem · Jul 05, 2017 at 08:00 PM 0
Share

Enums aren't int's by default, but they can be cast into int type by doing (int)quadrant.

So replace your current ifs like this

 if (initialQuadrant == 1 || initialQuadrant == 2)

With ones like this

 if ((int)initialQuadrant == 1 || (int)initialQuadrant == 2)

However, this kind of defeats the purpose of using enums. Why event use a Quadrant enum if your Quadrant is just an int?

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

66 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

Related Questions

Directly accessing enum types from other scripts (javascript) 0 Answers

Quaternion slerp loop exits before equality of quaternions 1 Answer

Flag structure variable in unity editor 1 Answer

hashtable: snapshot out of sync 2 Answers

Enum to int issue 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