2D Enemy AI problems.

Ok, I have 3 problems. I’m trying to make a pong game using this tutorial, #3. How to make a Simple 2D Game - Unity 5 Tutorial - YouTube,
but come up with these errors.

UnityException: Tag: Ball is not defined! Line 12.

NullReferenceException: Object reference not set to an instance of an object. Line 16

error CS1525: Unexpected symbol `GameObject’. Line 18.

Here is my code.

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {

public float speed = 8;
Vector3 targetPos;
GameObject ballObject;

void Start()
{
ballObj = GameObject.FindGameObjectWithTag ("Ball");
}

void Update ()
{
	targetPos = Vector3.Lerp (GameObject.transform.position,ballObj.transform.position,Time.deltaTime * speed)
	GameObject.transform.position = new Vector3 (20,targetPos.y,0);
}

}

Can somebody please help me? This is for the enemy AI.

Hi,

you have some spelling errors:
ballObject => ballObj
You are missing the semicolon after assigning targetPos.
Also you trying to acces the transform on the non static field GameObject.

I fixed the erros. Try the script below:

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour
{

    public float speed = 8;
    Vector3 targetPos;
    GameObject ballObj;
    void Start()
    {
        ballObj = GameObject.FindGameObjectWithTag("Ball");
    }
    void Update()
     {
         targetPos = Vector3.Lerp(transform.position, ballObj.transform.position, Time.deltaTime * speed);
         transform.position = new Vector3 (20,targetPos.y,0);
     }
}