NullReferenceException and UnityException problems.

I am currently trying to create a pong game from scratch and having a few problems with the code.

On line 12, I’m getting UnityException: Tag: Ball is not defined, and on line 16, I’m getting NullReferenceException: Object is not set to an instance of an object.

Here is the code.

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {

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

void Start() 
{
	Ball ball = GameObject.FindGameObjectWithTag ("Ball").GetComponent<Ball>();
}
void Update () 
{
	targetPos = Vector3.Lerp (gameObject.transform.position,ballObject.transform.position,Time.deltaTime * speed);
	gameObject.transform.position = new Vector3 (20, targetPos.y, 0);
}

}

Can someone please help me?

You need to create a “Ball” Tag. To create a tag, open the Tag drop-down list from the inspector and choose “Add a tag…”, Click here for more info about this.

The second error is telling you that “GameObject ballObject” has not been set up. Make it public and place a GameObject in it from the inspector.

http://unity3d.com/learn/tutorials/modules/beginner/editor/tags?playlist=17090