- Home /
CS0019: Operator `&&' cannot be applied to operands of type `int' and `bool'
Error CS0019: Operator && cannot be applied to operands of type int and bool Code: using UnityEngine; using System.Collections;
public class newChar : MonoBehaviour {
private int playerGender = 0;
private string[] genderStrings = {"Male", "Female"};
private int playerClass = 0;
private string[] classStrings = {"Knight", "Assassin", "Ranger", "Wizard"};
public bool chosen = false;
public GameObject maleKnight;
public GameObject femaleKnight;
public GameObject maleAssassin;
public GameObject femaleAssassin;
public GameObject maleRanger;
public GameObject femaleRanger;
public GameObject maleWizard;
public GameObject femaleWizard;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
playerGender = GUI.Toolbar (new Rect (25, 25, 300, 50), playerGender, genderStrings);
//Debug.Log(gender);
playerClass = GUI.Toolbar (new Rect (25, 100, 300, 50), playerClass, classStrings);
Debug.Log (playerClass);
if(playerClass = 0 && playerGender.Equals(0)){
Instantiate(maleKnight, Vector3.zero, Quaternion.identity);
}
if(playerClass = 0 && playerGender.Equals(1)){
Instantiate(femaleKnight, Vector3.zero, Quaternion.identity);
}
if(playerClass = 1 && playerGender.Equals(0)){
Instantiate(maleAssassin, Vector3.zero, Quaternion.identity);
}
if(playerClass = 1 && playerGender.Equals(1)){
Instantiate(femaleAssassin, Vector3.zero, Quaternion.identity);
}
if(playerClass = 2 && playerGender.Equals(0)){
Instantiate(maleRanger, Vector3.zero, Quaternion.identity);
}
if(playerClass = 2 && playerGender.Equals(1)){
Instantiate(femaleRanger, Vector3.zero, Quaternion.identity);
}
if(playerClass = 3 && playerGender.Equals(0)){
Instantiate(maleWizard, Vector3.zero, Quaternion.identity);
}
if(playerClass = 3 && playerGender.Equals(1)){
Instantiate(femaleWizard, Vector3.zero, Quaternion.identity);
}
}
}
Answer by Bunny83 · Jun 25, 2014 at 12:51 AM
You want:
if (playerClass == 0 && ...)
not
if (playerClass = 0 && ...)
Answer by meat5000 · Jun 25, 2014 at 12:51 AM
playerClass == 0
Two == for comparisions. This will then return a bool
Answer by Dracorat · Jun 25, 2014 at 12:52 AM
playerClass = 1
<- that's the assigment operator.
playerClass == 1
<- that's the comparison operator.
Also, you should enclose with parenthesis to ensure the logic happens as expected:
if((playerClass == 3) && (playerGender.Equals(0))){
Answer by tswalk · Jun 25, 2014 at 12:56 AM
(as mentioned above you've made an assignment, not a comparison operator)
instead of the iteration of conditionals.. in this case, it may be easier to do a switch.
switch(playerClass)
{
case 0:
if(playerGender.Equals(0))
{ //instantiate male... }
else
{ //instantiate female...}
break;
case 1:
// and so on...
}
Your answer
Follow this Question
Related Questions
bool[string] = true; array possible? 2 Answers
Distribute terrain in zones 3 Answers
GameObject variable doesn't get filled in 0 Answers
Multiple Cars not working 1 Answer
C# error - A namespace can only types and namespace declarations 2 Answers