Hi Im having some problems with created (prefab) gameObjects and a raycast. I've created some cubes in the game with BoxColliders and using:
to show me this in the editor. This works fine. I then created a new gameObject:
where newObject is a prefab created beforehand from a resource. What do I have to do to get the raycast working on this object? a box collider would do. I tried:
The gameObject gets a rigidbody and a boxcollider, but my raycast does not show up? Do I need to reinitiate something for the raycast to work? does the original file have to be somewhere else as in the resource file, with which I created the prefab. I checked the layers aswell, both are in Default.
Added complete script: its the: Debug.DrawLine (ray.origin, hit.point); not showing up whats bothering me. Im will add a colliderBox to the prefab to check if its something else. The DistanceToGround is confusing because I havent changed the Var name from the example I had, should be DistanceToCamera.
gameObject.layer = numOfLayer;
Regarding your main question we could use some info. You don't say how you create the ray, where your ground is and if/where you move the new object. If your ground is at (0,0,0) and you create a new object at the same position a raycast will probably not hit this object...
I checked your script and it works for me. Only thing I changed was the camera script:
It draws the rays for manually placed items as well as for instantiated prefabs. Maybe you should check out if the colliders are configured correctly on the instantiated prefabs?