Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
593 B
2
Indexable
Never
    void runLikeACoward(){
        agent.speed = originalSpeed * 2.5f;
        NavMeshHit hit;
        bool invalidLocation=true;
        

        while(invalidLocation){
            Vector3 randomDirection = new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
            desiredLocation = transform.position + randomDirection.normalized * 10;
            if(!NavMesh.SamplePosition(desiredLocation, out hit, 0.1f, NavMesh.AllAreas)) invalidLocation=true;
        }        

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