I’m trying to make a proximity AI script that will made an AI character chase a ball in a soccer game I am making for a school project. I’ve looked at multiple threads online and have asked for help from teachers and students.
This is the script I have. I have done something to improve it but I am still getting compiler errors.
public class GameObject Ball;
float range;
float speed;
Rigidbody rb;
void Start()
{
rb=GetComponent();
}
void Update()
{
range = Vector3.Distance(Ball.transform.position, transform.position);
if (range < 40)
{
transform.LookAt(Ball.transform.position);
}
if (range < 30 && range > 15)
{
rb.AddForce(Vector3.forawrd25speed);
}
}
These are the compiler errors that are popping up for me. I’ve tried multiple things to try and solve them but no matter what I do they still come up in the console log.
error CS1022: Type or namespace definition, or end-of-file expected
error CS0116: A namespace cannot directly contain members such as fields or methods
error CS1514: { expected
error CS1513: } expected
I am using Unity 2018.4.15f1, any help or tips on how to solve the problem would be very much appreciated.