Question by
unity_5OOQMqBpnrrSqw · Feb 16, 2018 at 01:14 PM ·
c#3dmovement script
I am having a problem with my 3d tdf enemy movement code. C#
Assets/Scripts/EnemyMovement.cs(4,14): error CS0101: The namespace global::' already contains a definition for
Enemy'
This is the error I have founded when designing my tower defense game. I seem to have found nothing besides this one error appear so far. Here is the current state of my code.:
using UnityEngine; using System.Collections;
public class Enemy : MonoBehaviour {
public float speed = 10f;
public float smooth = 2f;
private Transform target;
private int wavepointIndex = 0;
private Object waypoint;
void Start()
{
target = Waypoints.points[0];
InvokeRepeating("nextWaypoint", 0f, 0.5f);
}
void Update()
{
Vector3 dir = target.position - transform.position;
transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
if (Vector3.Distance(transform.position, target.position) <= 0.4f)
{
GetNextWaypoint();
}
}
void GetNextWaypoint()
{
if (wavepointIndex >= Waypoints.points.Length - 1)
{
Destroy(gameObject);
return;
}
wavepointIndex++;
target = Waypoints.points[wavepointIndex];
}
}
I think that my error is located within the first few lines of code. I could however be completely wrong.
Comment
Answer by yummy81 · Feb 16, 2018 at 01:27 PM
Somewhere else in your project files there is a class called Enemy. Just rename it.