• 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 RobertOne · Jul 05, 2017 at 09:30 AM · angleoperator

Operator `==' cannot be applied to operands

hey! iam trying to determinate a quadrant using this tiny Utilitie script:

 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 calling it like this:

 get
             {
                 Quadrant quadrant = Utilities.GetQuadrant(Utilities.Angle360(this.VelocityProjection, this.ForwardProjection));
                 return quadrant == 1 || quadrant == 2;
             }
             private set
             {

but this result in the following error: Operator ==' cannot be applied to operands of type Quadrant' and `int'

any idea why? thanks!

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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Jul 05, 2017 at 09:53 AM

Pretty much exactly as the error says - GetQuadrant returns a "Quadrant", but you're trying to compare it to an integer. I guess you meant to test it like this instead:

 return quadrant == Quadrant.I || quadrant == Quadrant.II;
Comment
Add comment · Show 1 · 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 RobertOne · Jul 05, 2017 at 09:56 AM 0
Share

oh damn, thanks - yes, totally :D

avatar image
0

Answer by NoseKills · Jul 05, 2017 at 09:58 AM

I presume Quadrant is an enum? You are trying to compare an enum value with an integer value

 return quadrant == 1 || quadrant == 2;

There's no implicit conversion from enum to an integer so the compiler can't understand how to perform the comparison: it can't know which integer Quadrant.III for example would equal.

You should probably use the enum's values to do the comparisons

 return quadrant == Quadrant.I || quadrant == Qudrant.II;

Or if you have some actual reason to stick to ints, you can do the enum to int casting explicitly

 return (int)quadrant == 1 || (int)quadrant == 2;

If you do the latter, it might be best to then also explicitly define the integer values of the enum so you can be certain the values are wht you think they are.

 enum Quadrant {
     I = 1,
     II = 2,
     ...
 }
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Apply force at an angle or transform.rotation 1 Answer

Need a little help with quick angle equation 2 Answers

Calculate vector3 from angle 2 Answers

Rotating A Character 180 Degress 1 Answer

Calculating a Second Set of Normals 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges