I try to Hit GameObject with this code
var ray = Camera.main.ScreenPointToRay(new Vector3(Camera.main.pixelWidth / 2, Camera.main.pixelHeight/2));
RaycastHit hit;
if (Physics.Raycast(ray,out hit,100))
{
print(hit.rigidbody.gameObject); //And make NullReferenceExeption error in this point
}
All game object i create with this code
public Object GrassPrefab;
// Use this for initialization
void Start ()
{
//
for (int x=0;x<20;x++)
for (int z = 0; z < 20; z++)
{
Instantiate(GrassPrefab,new Vector3(x,0,z),Quaternion.identity);
}
}