Here is the Code:
using UnityEngine;
using System.Collections;
public class Ai : MonoBehaviour {
Transform Ball;
Transform Enemy;
float step;
public float speed;
Transform midline;
void Start ()
{
Enemy = GameObject.Find ("Ball").transform;
}
void Update ()
{
if (Ball < 0)
{
gameObject.SetActive (false);
}
else
{
gameObject.SetActive (true);
step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position.x, Ball.position.x, step);
}
}
}
I am a beginner. So plz help me.