Hola, estoy estudiando la programacion siguiendo un libro que es de Unity, y llegue a un capitulo referente a la IA de Unity, este libro da ejemplos para poder comprender todo, entonses yo los tomo y practico un poco pero tengo un error en el uso de Linq al transformar un GameObject en transform, estaria muy agradecido de que me ayuden con el error, aqui les dejo el codigo y el error.
error recibido en la consola:
Assets/Enemy_AI.cs(46,75): error CS0029: Cannot implicitly convert type `UnityEngine.Transform[]' to `UnityEngine.GameObject[]'
Grasias por su atencion.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.AI;
using UnityEngine;
using System.Linq;
public class Enemy_IA : MonoBehaviour {
public enum Enemy_AI_State
{
IDLE = 2081823275, PATROL = 207038023,
CHASE = 1463555229, SEEKHEALTH = -833380208,
ATTACK = 1080829965
}
public Enemy_AI_State CurrentState = Enemy_AI_State.IDLE;
public bool CanSeePlayer = false;
public float DistEps = 0;
public float FieldOfView;
public int ChaseTimeOut = 2;
public LayerMask SightMask;
private GameObject[] waypoints;
private Animator ThisAnimator;
private Transform PlayerTransform;
private Transform ThisTransform;
private Collider ThisCollider;
private NavMeshAgent ThisAgent;
private bool HaveLineSightToPlayer(Transform Player)
{
float Angle = Mathf.Abs(Vector3.Angle(ThisTransform.forward,(Player.position-ThisTransform.position).normalized));
if (Angle > FieldOfView) return false;
if (Physics.Linecast(ThisTransform.position, Player.position, SightMask)) return false;
return true;
}
private void Awake()
{
ThisAnimator = GetComponent<Animator>();
ThisAgent = GetComponent<NavMeshAgent>();
ThisTransform = transform;
PlayerTransform = GameObject.FindGameObjectWithTag("Player").transform;
ThisCollider = GetComponent<BoxCollider>();
waypoints = GameObject.FindGameObjectsWithTag("Waypoints");
//ERROR
waypoints = (from GameObject GO in waypoints select GO.transform).ToArray(); //AQUI ESTA EL ERROR
//ERROR
}
private void Update()
{
CanSeePlayer = false;
if (!ThisCollider.bounds.Contains(PlayerTransform.position)) return;
CanSeePlayer = HaveLineSightToPlayer(PlayerTransform);
}
public IEnumerator State_Idle()
{
CurrentState = Enemy_AI_State.IDLE;
ThisAnimator.SetTrigger((int)Enemy_AI_State.IDLE);
ThisAgent.Stop();
while(CurrentState == Enemy_AI_State.IDLE)
{
if (CanSeePlayer)
{
StartCoroutine(State_Chase());
yield break;
}
yield return null;
}
}
public IEnumerator State_Patrol()
{
CurrentState = Enemy_AI_State.PATROL;
ThisAnimator.SetTrigger((int)Enemy_AI_State.PATROL);
Transform RandomDest = waypoints[Random.Range(0,waypoints.Length)];
ThisAgent.SetDestination(RandomDest.position);
while (CurrentState == Enemy_AI_State.PATROL)
{
if (CanSeePlayer)
{
StartCoroutine(State_Chase());
yield break;
}
if (Vector3.Distance(ThisTransform.position,RandomDest.position) <= DistEps)
{
StartCoroutine(State_Idle());
yield break;
}
yield return null;
}
}
public IEnumerator State_Chase()
{
CurrentState = Enemy_AI_State.CHASE;
ThisAnimator.SetTrigger((int) Enemy_AI_State.CHASE);
while (!CanSeePlayer)
{
float ElapsedTime = 0f;
while (true)
{
ElapsedTime += Time.deltaTime;
ThisAgent.SetDestination(PlayerTransform.position);
yield return null;
if(ElapsedTime >= ChaseTimeOut)
{
if (!CanSeePlayer)
{
StartCoroutine(State_Idle());
yield break;
}
else
{
break;
}
}
}
}
if(Vector3.Distance(ThisTransform.position,PlayerTransform.position) <= DistEps)
{
StartCoroutine(State_Attack());
yield break;
}
yield return null;
}
IEnumerator State_Attack()
{
yield return null;
}
}
error recibido en la consola:
Assets/Enemy_AI.cs(46,75): error CS0029: Cannot implicitly convert type `UnityEngine.Transform[]' to `UnityEngine.GameObject[]'
Grasias por su atencion.
