Hi Guys
So I am trying to get a raycast to stop at the first obstacle and not hit the objects next in line but so far no luck
I thought raycast was supposed to stop at first contact? but maybe I am doing something wrong.Anyway I put them both on the same mask layer.first is a large wall and the second is a sphere behind it.The ray keeps passing through the wall and hitting the sphere how can I prevent that?.
Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test raycast : MonoBehaviour
{ public GameObject first;
public GameObject second;
Bah I see what I did wrong.Just had to change the
rend2=second.GetComponent(); to
rend2.hit.collider.GetComponent();
The Debug.DrawLine(transform.position, hit.point, Color.yellow); got me where I needed to go.
Thx guys