I know how to do this with triggers and colliders but I don’t know how to do it with raycasting in place.
This is what I have for my raycast script so far:
using UnityEngine;
using System.Collections;
public class Raycasting : MonoBehaviour {
public bool hasHit = false;
public GameObject slotObject;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
RaycastHit hit;
float distcance = 5;
if(Physics.Raycast(transform.position, transform.TransformDirection(new Vector3(0,5,0)), out hit, distcance))
{
if(hit.collider.gameObject.tag == "Slot")
{
float distanceToObject = hit.distance;
slotObject = GameObject.FindGameObjectWithTag("Slot");
slotObject.renderer.material.color = Color.blue;
Debug.Log("Distance" + hit.distance);
}
}
Debug.DrawRay (transform.position, transform.TransformDirection(new Vector3(0,5,0)), Color.green);
}
}
It works ok when hitting an object, I just need to know how to make it know its hitting nothing.
Cheers