How to make an object affect time?

So basically I am making this top down game and when the character touches the time glass, it reduces the stopwatches time. (the lower the time, the better you are at the game)

This is currently my timscript code.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class timerscript : MonoBehaviour {

public Text timerText;//Link to this variable by dragging your UI textbox on the variable
public float timeLeft;//this is the variable that will show how much time you have spent playing the game

// Use this for initialization
void Start () {
timeLeft = 0f;//set to 10 seconds
}

// Update is called once per frame
void Update () {
//take a small amount of time off the variable everytime we enter the fram
timeLeft += Time.deltaTime;
//display time left
timerText.text = "Time: " + (Mathf.RoundToInt (timeLeft)) .ToString ();

}
}

Now for the character, I’m not sure what to do.

That script just looks like it’s counting down from 10 (maybe?) to zero.
What is it that you’re looking to accomplish, again? You want it so that touching the game object removes some time? Is that in addition to this countdown, or instead of it?

Make sure and use Code Tags when pasting code snippets into the forum.

So your stopwatch is constantly going up. I’ve added some public functions to handle changing the time from other classes:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class timerscript : MonoBehaviour {

    public Text timerText;//Link to this variable by dragging your UI textbox on the variable
    public float timeLeft;//this is the variable that will show how much time you have spent playing the game

    // Use this for initialization
    void Start() {
        timeLeft = 0f;//set to 10 seconds
    }

    // Update is called once per frame
    void Update() {
        AddTime(Time.deltaTime);

        //display time left
        timerText.text = "Time: " + (Mathf.RoundToInt(timeLeft)).ToString();

    }

    public void AddTime(float delta) {
        timeLeft += delta;
    }

    public void SubtractTime(float delta) {
        timeLeft -= delta;
    }
}

Make your time glass object, and give it a collider so that it can be touched by the player. Give it a script called “TimeGlass” or something.

It could be as simple as this:

public class TimeGlass : MonoBehaviour {
    public float timeValue; // set this in the inspector
}

Next make your character object, and give it a rigidbody and collider. You’ll need to configure the rigidbody correctly for your top-down view (gravity scale 0, etc) Then give it a script that implements a collision callback, take note that Unity functions are case-sensitive.

Within the collision callback, you check if the other object has the TimeGlass component. If so, you subtract from your Timer class.

Example of player:

public class Player : MonoBehaviour {

    private timerscript timer; // reference to the timer

    private void Awake() {
        timer = FindObjectOfType<timerscript>();
    }

    private void OnCollisionEnter2D(Collision2D collision) {
        // try to get a "TimeGlass" component from the other object
        TimeGlass timeGlass = collision.gameObject.GetComponent<TimeGlass>();
        // if it has the component
        if(timeGlass != null) {
            // subtract time
            timer.SubtractTime(timeGlass.timeValue);
            // destroy the pickup
            Destroy(timeGlass.gameObject);
        }
    }
}