Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
613 B
3
Indexable
Never
    void runLikeACoward(){
        agent.speed = originalSpeed * 2.5f;
        NavMeshHit hit;
        int i=0;
        
        do{
        Vector3 randomDirection = new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
        desiredLocation = transform.position + randomDirection.normalized * 10;
        i++;
        if(i>1) Debug.Log("Haven't hit anything, attempt " + (i - 1).ToString());
        } while (!NavMesh.SamplePosition(desiredLocation, out hit, 0.1f, NavMesh.AllAreas) || i>20);

        if(isCowarding) Invoke(nameof(runLikeACoward), 2);
        else agent.speed = originalSpeed;
    }