I have objects being spawned on the scene and they perform some actions when hit by Raycast.
If I drag a prefab to the scene manually it works fine, but if objects are respawned(so they are clones), they ignore raycast.
the code which launch those actions is the following:
public void Spin()
{
RaycastHit hit;
Ray ray = new Ray(camera.transform.position, transform.forward);
Debug.DrawRay(camera.transform.position, transform.forward, Color.green);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.CompareTag("spinner"))
{
hit.collider.gameObject.GetComponent<SpinnerController>().SpinItself();
}
else
{
Debug.Log("not a spinner");
gameObject.GetComponent<AudioSource>().PlayOneShot(loose);
}
}
}