How NavMesh Cost can slow down NavMeshAgent's speed?

Hi I have a terrain mesh and a water mesh in my scene. I make them in the different layer for Navigation. Terrain mesh in the “default” layer and water mesh in the “water” layer. I set the “water” layer’s cost to 100. What I want is the “water” layer still can walk through but it should make NavMeshAgent walk slowly if they have no choice need to go through the “water” area. But I dont know how to implement this. How can I get the NavMeshAgent’s layer cost for current position? How to determine the NavMeshAgent already in the “water” area?

Hello,
I found an answer (thank you to poster!) to a similar problem to the one in this old post somewhere but can’t seem to put my hand on the hyperlink…
anyway - you can sample the area where your unit is

var agent : NavMeshAgent;

function Start ()
{
agent = GetComponent(NavMeshAgent);
}


function Update ()
{
var navHit : NavMeshHit;
agent.SamplePathPosition (-1, 0.0f, navHit);
Debug.Log(navHit.mask);
}

you will get a bitfield result (Built-in areas: 1, 2, 4, user added areas : 8, 16, 32, 64, 128…) which you can use to identify your area index (0, 1, 2, 3 …) and therefore your area cost / speed / event, etc…
hope this helps if you stumble over this old post,

Create trigger areas to handle the speed modifier

[RequiredComponenet(typeof(Collider))]
public class TerrainTrigger : MonoBehaviour{

public float SpeedChange = -100;

OnTriggerEnter(collider Other){
other.SendMessage("SpeedChange",SpeedChange);
}
OnTriggerExit(collider other){
other.SendMessage("SpeedChange",-SpeedChange);
}
}

What about using Unity - Scripting API: AI.NavMeshAgent.FindClosestEdge

It find the closest Edge from the Agent, and return usefull information in the out parameter (including the mask composed of layers for this edge).

So this should work (untested!):

NavMeshHit lHit = new NavMeshHit();
if(FindClosestEdge(out lHit)
{
    if(lHit.mask & **N**) // where N is the number of the layer to test
    {
       //do here what you'll do for this layer
    }
}