- Home /
Question by
Kagutsuchi · Dec 01, 2013 at 02:40 PM ·
raycastcollider
Raycast: Different results depending on distance
Hi!
I'm wondering if I can get different results depending on the distance of a raycast?
This is what I want to do:
I want to display a GUI Text when 1 meter from the collider, but it won't disappear until I'm 1 meter from another collider. I want the GUI Text to disappear at a longer distance.
Is this at all possible?
Comment
Answer by belvita · Dec 02, 2013 at 08:38 PM
Of course it is possible.
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, -Vector3.up, hit,1)) {
var distanceToOtherobject= hit.distance;
Distancereached=true;
}
}
Then inside ongui function do something like
If (distancereached==true)
Show ur GUI text
Hope u get the idea
Your answer
Follow this Question
Related Questions
get custom class instance of collider hit by raycast? 1 Answer
Physics.Raycast not hitting anything 1 Answer
Detect only UI button click 3 Answers
Raycast to align character on MeshCollider normals 1 Answer
Raycast missing moving Collider 1 Answer