Help with AI c#

Ok so I am fairly new to unity/c# and I was trying to follow a youtube tutorial and I keep getting errors that i have been trying to fix for the past few hours.

using UnityEngine;
using System.Collections;

public class EnemyAI05 : MonoBehaviour {

public float moveForce = 0f;
private Rigidbody rbody;
public Vector3 moveDir;
public LayerMask whatIsWall;
public float maxDistFromWall = 0f;

// Use this for initialization
void Start () {

rbody = GetComponent();
moveDir = ChooseDirection (); <— ERROR HERE
Transform.rotation = Quaternion.LookRotation(moveDir);

}

// Update is called once per frame
void Update () {

Rbody.velocity = moveDir * MoveForce;

if(Physics.Raycast (Transform.position, Transform.forward, maxDistFromWall, whatIsWall))
{

moveDir = chooseDirection();
Transform.rotation = Quaternion.LookRotation(moveDir);
}

Vector3 ChooseDirection() AND another error in the first parentheses.
{

System.Random Ran = new System.Random();
int i = Ran.Next(0, 3);
Vector3 temp = new Vector3 ();

if (i == 0) {

temp = Transform.forward;
}
else if (i == 1)
{

temp = -Transform.forward;

}
else if (i == 2)
{

temp = -Transform.right;

}
else if (i == 3)
{

temp = -Transform.right;
}
return temp

Sorry if there is another way to post my code. it is my first time using the forums

2847547–207968–EnemyAI05.cs (1.07 KB)

hello, you didn’t posted the error. So we have no idea what to look for.

I found two missing }

using UnityEngine;
using System.Collections;

public class EnemyAI05 : MonoBehaviour {

    public float moveForce = 0f;
    private Rigidbody rbody;
    public Vector3 moveDir;
    public LayerMask whatIsWall;
    public float maxDistFromWall = 0f;




    // Use this for initialization
    void Start () {
   
        rbody = GetComponent<Rigidbody>();
        moveDir = ChooseDirection ();
        Transform.rotation = Quaternion.LookRotation(moveDir);
    }
   
    // Update is called once per frame
    void Update () {
   
        Rbody.velocity = moveDir * MoveForce;

        if(Physics.Raycast (Transform.position, Transform.forward, maxDistFromWall, whatIsWall))
        {

            moveDir = chooseDirection();
            Transform.rotation = Quaternion.LookRotation(moveDir);
        }
    }  // <=== missing


        Vector3 ChooseDirection()
    {

    System.Random Ran = new System.Random();
    int i = Ran.Next(0, 3);
    Vector3 temp = new Vector3 ();
   
    if (i == 0) {
   
            temp = Transform.forward;
        }
        else if (i == 1)
        {
   
            temp = -Transform.forward;

    }
        else if (i == 2)
        {
           
            temp = -Transform.right;

    }
        else if (i == 3)
        {
           
            temp = -Transform.right;
        }
        return temp
} // <=== missing

https://forum.unity3d.com/threads/using-code-tags-properly.143875/

stickies are a wonderful thing… so unloved :frowning:

I see more, C# is case sensitive.
Rbody.velocity= moveDir * MoveForce;
rbody and moveForce

Vector3 ChooseDirection()
and moveDir = chooseDirection();

; was missing on the return temp line

temp = -Transform.right; needs to be temp = -transform.right;
Transform is a class, transform is a Vector3

updated code:

using UnityEngine;
using System.Collections;

public class EnemyAI05 : MonoBehaviour {

    public float moveForce = 0f;
    private Rigidbody rbody;
    public Vector3 moveDir;
    public LayerMask whatIsWall;
    public float maxDistFromWall = 0f;




    // Use this for initialization
    void Start () {

        rbody = GetComponent<Rigidbody>();
        moveDir = ChooseDirection ();
        transform.rotation = Quaternion.LookRotation(moveDir);



    }

    // Update is called once per frame
    void Update () {

        rbody.velocity = moveDir * moveForce;

        if(Physics.Raycast (transform.position, transform.forward, maxDistFromWall, whatIsWall))
        {

            moveDir = ChooseDirection();
            transform.rotation = Quaternion.LookRotation(moveDir);
        }
    }


    Vector3 ChooseDirection()
    {

        System.Random Ran = new System.Random();
        int i = Ran.Next(0, 3);
        Vector3 temp = new Vector3 ();

        if (i == 0) {

            temp = transform.forward;
        }
        else if (i == 1)
        {

            temp = -transform.forward;

        }
        else if (i == 2)
        {

            temp = -transform.right;

        }
        else if (i == 3)
        {

            temp = -transform.right;
        }
        return temp;
    }

}

Alright this fixed all of the errors thanks. And i will make sure to use stickies from now on.