how to make a boost pad

i,m trying to make a boost pad that increases the players speed when the player goes onto it then decreases back to normal after. this is my script, any help would be great. thanks.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class playerController : MonoBehaviour {

public float speed;
public Text countText;
public Text winText;

private Rigidbody rb;
private int count;

void Start ()
{
	rb = GetComponent<Rigidbody> ();
	count = 0;
	//SetCountText ();
	winText.text = "";
}

void FixedUpdate ()
{
	float moveHorizontal = Input.GetAxis ("Horizontal");
	float moveVertical = Input.GetAxis ("Vertical");

	Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

	rb.AddForce (movement * speed);
}

void OnTriggerEnter(Collider other)
{
	if (other.gameObject.CompareTag ("PickUp")) 
	{
		other.gameObject.SetActive (false);
		count = count + 1;
		//SetCountText ();
	} else {
        if (other.gameObject.CompareTag("Boost"))
        {
            speed = 20f;
        }
        else
        {
            speed = 10;
        }
     }
}

public class playerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;

 private float boostDuration = 3f;
 private Coroutine boostCoroutine;
 
 void Start ()
 {
     rb = GetComponent<Rigidbody> ();
     count = 0;
     //SetCountText ();
     winText.text = "";
 }
 void FixedUpdate ()
 {
     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");
     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
     rb.AddForce (movement * speed);
 }
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag ("PickUp")) 
     {
         other.gameObject.SetActive (false);
         count = count + 1;
         //SetCountText ();
     } else {
         if (other.gameObject.CompareTag("Boost"))
         {
			 StopBoost();
			 boostCoroutine = StartCoroutine(Boost());
         }
         else
         {
             speed = 10;
         }
      }
 }
 
 IEnumerator Boost()
 {
	speed = 20f;
	yield return new WaitForSeconds(boostDuration);
	speed = 10f;
 }
 
 void OnDestroy()
 {
	StopBoost();
 }
 
 void StopBoost()
 {
	 if(boostCoroutine == null)
	 {
		StopCoroutine(boostCoroutine);
		boostCoroutine = null;
	 }
 }

I assume that modification should work. Within IEnumerator Boost you can do whatever you want with boost :slight_smile:

The solution was made using Coorutine, you should check the link below:

https://docs.unity3d.com/Manual/Coroutines.html