Check color based on distance

So I’m trying to check the distance of my ball from a platform, and check whether it can land on it, if they’re not the same color it cannot and if it is it will collide. It’s giving me an error “Use of unassigned local variable `closest’”
this is my ball script

	GameObject FindClosestPlatform() {
		GameObject[] gos;
		gos = GameObject.FindGameObjectsWithTag ("Platform");
		GameObject closest;
		float distance = Mathf.Infinity;
		Vector3 position = transform.position;
		foreach (GameObject go in gos) {
			Vector3 diff = go.transform.position - position;
			float curDistance = diff.sqrMagnitude;
			if (curDistance < distance) {
				closest = go;
				distance = curDistance;
		return closest;

	public void closeColor(){

		var close = (FindClosestPlatform().renderer.material.color);
		var ballcolor = (ball.renderer.material.GetColor ("_Color"));
		if (close != ballcolor)

			Physics2D.IgnoreLayerCollision(8,9, true);
		}else if (close == ballcolor){
			Physics2D.IgnoreLayerCollision(8,9, false);
			rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x, 8);
void OnTriggerEnter2D (Collider2D col){

	closeColor ();


When you declare

GameObject closest;

you don’t give closest a value, and c# doesn’t like that.
You should probably turn that into something like

GameObject closest = null;