- Home /
Operator '==' cannot be used!
Hello,I've this problem respect to "switch"....You watch my part of script... Please,help me!
public var WeaponType : TypeOfWeapon;
enum TypeOfWeapon
{
M9,
ScarH,
M4A1,
ACR,
MP5,
STRIKER,
FIVESEVEN,
P99,
MINIUZI,
UMP45,
AK
};
function Update(){
switch(TypeOfWeapon)
{
case TypeOfWeapon.M9:
BulletVelocity = 1000;
Ammo = 30;
totalAmmo = 30;
BulletDamage = 25;
SingleFire = true;
break;
case TypeOfWeapon.ScarH:
BulletVelocity = 1000;
Ammo = 100;
totalAmmo = 100;
BulletDamage = 54;
RapidFire = true;
RateOfFire = 0.220000;
break;
}
}
In Console there's this problem:
Assets/Scripts/WeaponShootManager.js(70,9): BCE0051: Operator '==' cannot be used with a left hand side of type 'System.Type' and a right hand side of type 'TypeOfWeapon'.
Answer by tanoshimi · Apr 06, 2014 at 01:13 PM
TypeOfWeapon is an enum. In your switch statement you should be comparing the value of a variable that has been set to one of those enumerated states, e.g
switch (currentlySelectedWeapon) { case TypeOfWeapon.Knife:...
Answer by haim96 · Apr 06, 2014 at 01:20 PM
this might help you... http://answers.unity3d.com/questions/15250/how-to-declare-and-use-a-enum-variable-in-javascri.html
Your answer
Follow this Question
Related Questions
Cycling through enum with key press 1 Answer
What is a more efficient way to write this Switch Statement? 3 Answers
How to check if an enum’s case has changed 3 Answers
Switch case using enum javascript 2 Answers
Changing enum values 1 Answer