Exemplo n.º 1
0
    //overall coroutine - this dictates when behaviour movement can occur,
    //and also handles material setting
    IEnumerator Movement(string _subCoroutineName)
    {
        while (true)
        {
            if (m_GotoComponent.bCanMove() && m_GotoComponent.ObjectFound &&
                gameObject.GetComponent <FlrMain>().BehvrEnabled)
            {
                //get new position of the object to move to, set the material
                m_v3ObjToMoveToCurrPos = m_GotoComponent.ObjectFound.transform.position;
                vSetMaterial(m_MatGo);

                //if the object is within set range
                //ignore behaviour and move towards it
                if (m_GotoComponent.fDistToTarget < m_fIgnoreBehaviourRange)
                {
                    StartCoroutine("BaseMove", m_fMovementInterval - 0.05f);
                }
                else
                {
                    StartCoroutine(_subCoroutineName, m_fMovementInterval - 0.05f);
                }
            }
            //else no object or cannot move, so goto idle material
            else
            {
                vSetMaterial(m_MatIdle);
            }

            yield return(new WaitForSeconds(m_fMovementInterval));
        }
    }