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