This is the comparison I am making:
if (aiController.attackTarget ==
entity)
aiController.attackTarget is of type LivingEntity and entity is of type AIController. Can I compare these 2 different types because of inheritance? Can I say, an AIController is a LivingEntity.
This is the setup I am using:
IEntity (interface)
using UnityEngine;
public interface IEntity
{
Vector3 position { get; set; }
GameObject gameObject { get; }
}
Entity.cs (base class)
using UnityEngine;
public abstract class Entity : MonoBehaviour, IEntity
{
public Vector3 position
{
get { return this.transform.position; }
set { this.transform.position = value; }
}
}
LivingEntity.cs
using UnityEngine;
public abstract class LivingEntity : Entity
{
private LivingEntity _attackTarget;
public LivingEntity attackTarget
{
get { return _attackTarget; }
set { _attackTarget = value; }
}
}
AIController.cs
using UnityEngine;
public class AIController : LivingEntity
{
// Stuff
}