Exemplo n.º 1
0
    // Distract enemy by making them look towards the distraction, then resume patrolling after distract time
    public void Distract(Vector2 distractPos)
    {
        Vector2 diff;           // Difference between this objects position and the position of the distraction

        // Stop movement and set distracted to true
        distracted = true;
        Stop();

        // Calculate difference
        diff = distractPos - (Vector2)(transform.position);

        // If difference is not negligibly small, make enemy look towards it
        if (diff.sqrMagnitude > 0.2f)
        {
            currentSightDir = diff;
        }
        // Otherwise, just make them turn around
        else
        {
            currentSightDir = -currentSightDir;
        }

        // Make enemy look confused
        effects.Emote(true, EnemyEmotes.Confused);
        effects.EnableDistractSlider(true, distractTime);

        // Cause enemy to resume patrol after distraction is up
        Invoke("ResumePatrol", distractTime);
    }