raycast hit doesn't seem to work

hi,
i want to compare the name of a prefab that gets instantiated and print a something, but the condition doesn’t seem to work.need help in this.

using UnityEngine;
using System.Collections;

public class prefabCreation_1 : MonoBehaviour {

	//public GameObject startbutton;
	public GameObject button;

	bool onGameMode = true;


	void Update()
	{ 
		Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		RaycastHit hit;

		if(onGameMode == true)
		{ 
			Instantiate(button, transform.position,transform.rotation);
			//prefabCreation();
		}

		if (Physics.Raycast (ray, out hit, 100)) 
		{
			if(Input.GetMouseButtonUp(0))
			{
				if(hit.collider.gameObject.name == "startButton")
				{
					print ("working");
				}
			}
		}

		onGameMode = false;
	}

Why did you include this check

if(Input.GetMouseButtonUp(0))

Remove it. You should check it before raycast.

Also, try printing the name of the object in the console. That will help you to find which collider it hits.

You don’t have to put Physics.Raycast in if statement.

Physics.Raycast (ray, out hit, 100);
if(Input.GetMouseButtonUp(0))
{
   if(hit.collider.gameObject.name == "startButton")
   {
       print ("working");
   }
}