Question by
djanthony93 · Oct 05, 2016 at 05:07 PM ·
scripting problemraycastcollider
How to pop up a text when my first person ray hit an object
Hello, I'm trying to make a script that allows my first person character to pop up GUI text (object name) on the screen when my distance ray hits an object. This is my starting point:
using UnityEngine;
using System.Collections;
public class RaycastPlayer : MonoBehaviour {
public float distanceToSee;
RaycastHit whatIHit;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Debug.DrawRay(this.transform.position, this.transform.forward * distanceToSee, Color.magenta);
}
}
Basically when I run my game it display the ray distance as a magenta line. I have tried using the OnColliderEnter void function to display the object name in the Debug Log but it won't work. Any suggestion?
Comment