- Home /
Question by
BondableAtom · Aug 06, 2014 at 06:32 PM ·
c#error
Error: error CS0029: Cannot implicitly convert type `UnityEngine.GameObject[]' to `UnityEngine.GameObject
Hi, how can I fix this:
error CS0029: Cannot implicitly convert type UnityEngine.GameObject[]' to
UnityEngine.GameObject
Script:
using UnityEngine;
using System.Collections;
public class EnemyMovement : MonoBehaviour {
public int rotateSpeed = 1;
public int movementSpeed = 1;
private Transform myTransform;
public Transform target;
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectsWithTag("Player");
target = go.transform;
myTransform = transform;
}
// Update is called once per frame
void Update () {
Rotate();
}
void Rotate () {
Debug.DrawLine (myTransform.position, target.position, Color.red);
}
}
Comment
Best Answer
Answer by gjf · Aug 06, 2014 at 06:16 PM
GameObject go = GameObject.FindGameObjectsWithTag("Player");
returns an array and not a single game object . Try using FindWithTag() instead.
also, try to include the complete error message including line numbers.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Have null errors 1 Answer
error cs0120 1 Answer
SendMessage setName has no receiver! 1 Answer
Argument out of range. 1 Answer