- Home /
Question by
Beta_Artist · Sep 27, 2011 at 08:30 PM ·
movementaiswitch
Switch Case for Basic AI....
Here's the problem, I'm trying to make the AI react to the player's mouse. By clicking the AI, we will call Bob, you can have Bob randomly change his direction. The problem is that when I try to click Bob, he doesn't move anywhere other then the default direction.
The Code:
var speed = 5;
var deer = 10;
var tap = 100;
var rotate;
function Update () {
transform.position += transform.forward * Time.deltaTime * speed;
}
function OnMouseEnter() {
speed = 15;
TotalScoreScript.Points += deer + 10;
}
function OnMouseExit () {
speed = 5;
}
function OnMouseDown () {
TotalScoreScript.Points += tap + 100;
}
function ChangeDirection() {
dir = Random.Range(2,-2);
switch(dir){
case -2:
rotate = -135;
break;
case -1:
rotate = -45;
break;
case 1:
rotate = 45;
break;
case 2:
rotate = 135;
break;
default:
rotate = 0;
break;
}
if(rotate!=0){
transform.Rotate(Vector3.up, rotate);
}
}
Comment
Answer by aldonaletto · Sep 27, 2011 at 11:20 PM
The character doesn't change direction because you are never calling ChangeDirection()! Insert in OnMouseDown:
function OnMouseDown () { TotalScoreScript.Points += tap + 100; ChangeDirection(); }