# I need a little help with AI script (C#)

Im doing a semple script for AI in my game and i need a little help … what is the problem with my script ?`using UnityEngine;
using System.Collections;

public class WeakAI : MonoBehaviour {

``````float Distance;
public Transform Target ;
double lookAtDistance = 25.0;
double attackRange = 15.0;
float moveSpeed = 5 ;
double Damping = 6.0;

void Update ()
{
Distance = Vector3.Distance(Target.position, transform.position);

if (Distance < lookAtDistance)
{
renderer.material.color = Color.yellow;
lookAt();
}

if (Distance > lookAtDistance)
{
renderer.material.color = Color.green;
}

if (Distance < attackRange)
{
renderer.material.color = Color.red;
attack ();
}
}

void lookAt ()
{
Transform rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}

void attack ()
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
``````

`

In your variables, you are using several doubles. Using doubles will cause you some pain because everything in Unity deals with floats. This means you will have to cast your values all over the place to make things work (and therefore won’t get any benefit from using doubles). A literal float value can be made by appending an ‘f’ or an ‘F’ to the end of the value. So the top part of your script could be:

``````float Distance;
public Transform Target ;
float lookAtDistance = 25.0f;
float attackRange = 15.0f;
float moveSpeed = 5.0f ;
float Damping = 6.0f;
``````

The ‘real’ problem is line 32. Rotations are not transforms. The are Quaternions, so line 32 should be:

``````Quaternion rotation = Quaternion.LookRotation(Target.position - transform.position);
``````