Problem in creating obstacle that makes the gameobject slow.

I facing problem in creating a function that the obstacle causes the slow effect to the gameobject which collide with it
below is my coding and the game object is using the 1st person controller that only will moves forward with controller left and right and jump as well.

public static float speed= 0.15f;
	void OnTriggerStay(Collider other)
	{
		if (other.tag == "Obstacle")
		{
			transform.Translate(Vector3.forward * 0);

			//yield return new WaitForSeconds (3);
		}
	}
	public void Update() 
	{
        transform.Translate(Vector3.forward * speed)	
	}
}

Guides and helps is needed.
thanks and regards.

You would most time need to get to the var that controls speed to you character motor/walker script.

If you create a gameObject that is used for a trigger.
try (ie) gameObject.FindWithTag(“Player”) on the trigger and then go with GetComponent to get to the script and variable you need to adjust.

Or you can create a static var on your characterMotor/Walker that can adjust your speed var in update.

Then from there you can then place on your triggerScript
(ie) MotorScriptname.speedAdjusterVar = 2;

And then OnTriggerExit set it back to the old value.

Thanks for the help. and it is very helpful =).
Another question i would like to ask which is there anywhere to delay the effect of slow for about 2 second instead of using the OnTriggerExit function which restore the immediate speed right after passing through the obstacle?
Thanks.

In OnTriggerEnter you can create a delay for a period, with Invoke. Then returning the var value back to original.

var trigState : Int;
OnTriggerEnter (col : Collider) {

if((col.gameObject.tag==“Player”)(trigState==0)) {
PlayerMotorScriptName.speedVar = 2;//Poison Sting/WhatEver
trigState = 1;
Invoke(“Delay_0A”,3);

}
}
//---------------------------------------------------------------------------------//
function Delay_0A() {
PlayerMotorScriptName.speedVar = 10;//Original
Invoke(“RepeatDelay”,2);//cant go again till time is up
}
//---------------------------------------------------------------------------------//
function RepeatDelay() {
trigState = 0;//reset
}

Something like this example may do the trick.

thanks black mantis.
that’s exactly what i want.
Thank you very much. =)