How do I add time to timer with C#?

I’m trying to add time to a timer, which I named and tagged Timer. This script will be attached to various game objects. When the player collides with these objects it should add 10/20 seconds on the GUI timer. I’ve been trying to figure this out for 3 days, I found examples in Java which I’ve tested with no luck. I’ve watched tutorials, tried a lot of things out, it always shows errors. This is the first time i’ve done programming so learning a lot, this is the last bit of code left for the gameplay. I would appreciate some help or advise in making this work.

What I got here works so far to destroy objects on collision and add points, just need it to add time.

Harry

using UnityEngine;
using System.Collections;

public class ScorePoint : MonoBehaviour {
	
	void OnTriggerEnter2D(Collider2D collider) {
				if (collider.tag == "Player") {
						Score.AddPoint ();
						gameObject.SetActive (false);
				}

		}
}

This is my timer script:

using UnityEngine;
using System.Collections;

public class Timer : MonoBehaviour
{
public float Seconds = 59;
public float Minutes = 1;

void Update()
{
	if(Seconds <= 0)
	{
		Seconds = 59;
		if(Minutes >= 1)
		{
			Minutes--;
		}
		else
		{
			Minutes = 0;
			Seconds = 0;
			GameObject.Find("Timer").guiText.text = Minutes.ToString("f0") + ":0" + Seconds.ToString("f0");
		}
	}
	else
	{
		Seconds -= Time.deltaTime;
	}

	

	if(Mathf.Round(Seconds) <= 9)
	{
		GameObject.Find("Timer").guiText.text = Minutes.ToString("f0") + ":0" + Seconds.ToString("f0");
	}
	else
	{
		GameObject.Find("Timer").guiText.text = Minutes.ToString("f0") + ":" + Seconds.ToString("f0");
	}
	{
		if(Seconds <= 0.0) {
			Application.LoadLevel("GameOver");
		}
}

}
}

You should not attach the timer to various GameObjects, this way you will have various timers. Attach the Timer script to an empty object and collision detectors to those various objects. When detecting collision, refer to the Timer class from the collision detector class and do the stuff.

Didn’t test this snippet but it might be what you’re looking for.

using System;

private float seconds = 59f;

void Update()
{
    if(seconds > 0f) 
    {
        seconds -= Time.deltaTime;

        TimeSpan timeSpan = TimeSpan.FromSeconds(seconds);
        string timeLeft = string.Format("{0:D2}:{1:D2}", timeSpan.Minutes, timeSpan.Seconds);
        GameObject.Find("Timer").guiText.text = timeLeft;
    }
    else
    {
        Application.LoadLevel("GameOver");
    }
}

public void AddBonusTime(float bonusTime)
{
    seconds += bonusTime;
}

As @maddFrogg suggested, there should be only one timer object.