Question by
Commander-Rabbit · Nov 13, 2016 at 08:45 AM ·
ienumerator
IEnumerator keeps saying not all code paths return values
on the IEnumerator hitting Its saying not all code paths return a value I'm so confused I'm doing the same as everyone else please tell me what I did wrong!!!
public class BasicAI : MonoBehaviour {
private NavMeshAgent agent;
private Animator Animator;
public float Health = 200;
public float DistanceToHit;
public float Damage;
public bool Chase;
private bool IsChasing;
public bool Wander;
public bool PickWander;
public bool Dead = false;
public bool CanHit = false;
public bool Touching = false;
public bool Hit = false;
public bool hitting = true;
private Transform PlayerTransform;
public Transform WanderRight;
public Transform WanderLeft;
public Transform WanderForward;
public Transform WanderBackward;
public Transform WanderStay;
public Transform WanderPlace;
private float HowFarFromPlayer;
// Use this for initialization
void Start () {
Animator = GetComponent<Animator>();
agent = GetComponent<NavMeshAgent>();
}
private void OnCollisionStay(Collision collision)
{
if (collision.collider.GetComponent<Player>())
{
if (Dead == false)
{
collision.collider.GetComponent<Player>().health -= 20;
Touching = true;
CanHit = true;
}
}
}
private void OnCollisionExit(Collision collision)
{
if (collision.collider.GetComponent<Player>())
{
Touching = false;
CanHit = false;
}
}
private void OnTriggerEnter(Collider target)
{
if (target.GetComponent<Player>())
{
PlayerTransform = target.transform;
IsChasing = true;
}
}
private void OnTriggerExit(Collider target)
{
if (target.GetComponent<Player>())
{
PlayerTransform = null;
IsChasing = false;
}
}
IEnumerator Hitting()
{
}
void Update () {
Animator.SetBool("Walk", IsChasing);
Animator.SetBool("Die", Dead);
if (PlayerTransform != null)
{
HowFarFromPlayer = Vector3.Distance(gameObject.transform.position, PlayerTransform.transform.position);
}
//Health Die
if(Hit == true)
{
hitting = true;
StartCoroutine(Hitting());
}
if (IsChasing == true)
{
if (HowFarFromPlayer <= DistanceToHit)
{
Hit = true;
}
}
if (Health <= 0)
{
IsChasing = false;
Dead = true;
agent.SetDestination(gameObject.transform.position);
Destroy(gameObject,3);
}
if(IsChasing == false)
{
agent.SetDestination(gameObject.transform.position);
}
if(IsChasing == true)
{
agent.SetDestination(PlayerTransform.transform.position);
}
}
}
Comment
Answer by Raresh · Nov 13, 2016 at 08:49 AM
The error is pretty clear isn't it? Your IEnumerator needs to return something. It's almost as having a function that needs to return an int for example (but not really).
Read this again: https://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html
Your answer
Follow this Question
Related Questions
IENumerator does not work 0 Answers
Problem with color Change 2 Answers
Freezing GameObject in place using collider trigger? 1 Answer
Click two buttons at the same time 0 Answers
Public IEnumerator wont work if attached to a button. 0 Answers