How to make character slow down on collision

In my game, a human character is being chased by wild bulls in a straight narrow path. While running he hits a banana that caused his speed to be slowed down. Scripting wise how do i do that?

Is it something to do with OnTriggerEnter?

Yup. Any script with a function called OnTriggerEnter(Collider other) will fire whenever something enters that object’s trigger. You can use that to run code. The easiest way for objects to interact is to use SendMessage() For example, you could attach a script to your banana that includes the following:

OnTriggerEnter(Collider other){
    //first we make sure that the object that hit the banana is the player.
    if (other.name == "Player"){ 
        // This will search all player scripts for a function called "Hit Banana"
        print ("Banana was hit by player");
        other.gameObject.SendMessage("HitBanana");
    }
}

Then in whatever script controls player movement…

function HitBanana(){
    speed -= 4;
    print ("Player successfully slowed");
}

Here’s a tutorial on collisions that might help:

Unity Tips and Tricks: Physical Interactions with Collisions and Triggers

It’s a quick one that will give you a pretty good idea on how collisions are handled in Unity. Good luck!

you could try:

// javascript
public var bannana : GameObject;

function OnCollisionEnter(collision : Collision) {
	if(collision.gameObject == bannana)
	{
		Time.timeScale = 0.2;
	}
	else
	{
		Time.timeScale = 1;
	}
}

note: untested

If you have a float or int value for the Player’s movement speed

public float movementSpeed = 10f;

Then you can directly access that by setting a new value

 movementSpeed = 5f;

If you wanted to do this in a OnTriggerEnter function

void OnTriggerEnter(Collider col)
{
   if(col.gameobject.tag == "Player")
   {
       // Call the slow down function or set the new movement speed
   }
}

I wouldn’t use “Time.timeScale” as it would slow down the whole game including the enemy, also any other scripts that use the current time as a calculation (E.g Score incrementing by time)