Exemplo n.º 1
0
    ///////////////////////////////////////////////////////////////////////////

    bool HandleWaypointChange()
    {
        Vector3 targetPoint    = GetTargetPoint();
        Vector2 selfToTarget2D = (targetPoint - transform.position).xz();

        float distanceToTarget = selfToTarget2D.magnitude;

        if (distanceToTarget < ReachTargetThreshold)
        {
            int pathPointCount = WalkerPath.Get().PathLines.Length;
            m_CurrentTargetPointIndex++;

            if (m_CurrentTargetPointIndex >= pathPointCount)
            {
                GameManager.Get().m_RescuedWalkers++;
                GameManager.Get().AddTimeBonus(TimeBonusWhenRescued);
                AudioManager.Get().PlayRandomOneShot(WalkerManager.Get().gameObject, WalkerManager.Get().RescueSound, WalkerManager.Get().RescueSoundVolume);
                m_CurrentTargetPointIndex--;
                GameObject.Destroy(gameObject);
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 2
0
    public static WalkerPath Get()
    {
        if (!s_Instance)
        {
            s_Instance = GameObject.FindObjectOfType <WalkerPath>();
            s_Instance.ReInit();
        }

        return(s_Instance);
    }
Exemplo n.º 3
0
    ///////////////////////////////////////////////////////////////////////////

    Vector3 GetTargetPoint()
    {
        int pathPointCount = WalkerPath.Get().PathLines.Length;

        if (pathPointCount == 0 || m_CurrentTargetPointIndex >= pathPointCount)
        {
            Debug.Assert(false);
            return(Vector3.zero);
        }

        float   fixedRnd  = VectorExtensions.GetFixedRandom(ID);
        Vector3 pathPoint = WalkerPath.Get().PathLines[m_CurrentTargetPointIndex].GetLerped(fixedRnd);

        return(pathPoint);
    }
Exemplo n.º 4
0
    ///////////////////////////////////////////////////////////////////////////

    public void Reorient()
    {
        int   bestIndex           = 0;
        float bestDistance        = float.MaxValue;
        bool  bestLiesInFrontOfUs = false;

        Vector2 ownPos = transform.position.xz();

        for (int i = 0; i < WalkerPath.Get().PathLines.Length; ++i)
        {
            Vector2 curPoint = WalkerPath.Get().PathLines[i].GetLerped(0.5f).xz();
            float   distance = Vector2.Distance(ownPos, curPoint);

            if (distance < bestDistance)
            {
                bestDistance = distance;
                bestIndex    = i;

                if (i == WalkerPath.Get().PathLines.Length - 1)
                {
                    bestLiesInFrontOfUs = true;
                }
                else
                {
                    Vector2 nextPoint = WalkerPath.Get().PathLines[i + 1].GetLerped(0.5f).xz();

                    bestLiesInFrontOfUs = Vector2.Dot(nextPoint - curPoint, curPoint - ownPos) > 0;
                }
            }
        }

        if (!bestLiesInFrontOfUs && bestIndex < WalkerPath.Get().PathLines.Length - 1)
        {
            bestIndex++;
        }

        m_CurrentTargetPointIndex = bestIndex;
    }