I have a script but I don’t know how to add certain classes in or things. Could you show me?
//wall Boundaries
float wall_left = 5.0f;
float wall_right = Screen.width - 5.0f;
float wall_top = Screen.height - 5.0f;
float wall_bottom = 5.0f;
//AI properties
Vector2 AI_Position;
float Speed = 0.3f;
//Get two Random values within a Range (Screen dimensions)
float randomX = Random.Range(0,Screen.width);
float randomY = Random.Range(0,Screen.height);
//Create a Vector2 out of the Random values
Vector2 randomXY = new Vector2(randomX,randomY);
//Get the Direction from AI to the RandomXY generated
Vector2 Direction = randomXY - AI_Position;
//Normalize the Direction to apply appropriatly
Direction = Direction.normalized;
//Check that your AI is within your boundaries
if( AI_Position.x > wall_left && AI_Position.x < wall_right
&& AI_Position.y > wall_bottom && AI_Position.y < wall_top )
{
//Make AI move in the Direction (adjust speed to your needs)
AI_Position += Direction * Speed;
}
else
{
//make your AI do something when its not within the boundaries
//maybe generate a new direction?
}