Assets/Movement.cs(24,21): error CS0019: Operator `==' cannot be applied to operands of type `bool' and `int'
Im making a sort of random movement AI for enemies, where the direction they would go is determined by the numbers 1-4 randomly chosen by the Random.Range(1,4)
command.
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public int moveSpeed = 10;
public int computerDirection;
Vector3 moveDirection = new Vector3(-1, 0, 0);
bool movingLeft = false;
bool movingRight = false;
bool movingUp = false;
bool movingDown = false;
bool Movementnumber = Vector3(Random.Range(1,5));
// Use this for initialization
void Start () {
}
void update (){
Coroutine(Movement);
int Movementnumber = Vector3(Random.Range(1,4));
}
public Movement(){
if (Movementnumber == 1){
moveDirection = new Vector3 (1, 0, 0);
movingLeft = true;
}
if (Movementnumber == 2){
moveDirection = new Vector3 (-1, 0, 0);
movingRight = true;
}
if (Movementnumber == 3){
moveDirection = new Vector3 (0, 1, 0);
movingRight = true;
}
if (Movementnumber == 4){
moveDirection = new Vector3 (0, -1, 0);
movingRight = true;
}
}
When i try to use Random.Range this way, i always get a error which tells me that '==' can't be applied to bool and int. I don't know what is actually happening in this case, since im just saying for that section of the code to initiate when 'Random.Range(1,4)' reaches one of those numbers, and that the 'Movementnumber' is supposed to be that number which is randomly picked. Am i missing something in all this?
Cleaned up the code formatting. $$anonymous$$oved to Help Room. CS0019 could not be added as topic....
Answer by Linus · Oct 11, 2015 at 12:47 PM
You are setting Movementnumber to be a Vector3.
// int Movementnumber = Vector3(Random.Range(1,4));
//Should be int
int Movementnumber = Random.Range(1,4);
Also, you have a lower u in update. It should be Update()