Skip to content

Commit 370eaf2

Browse files
authored
Create RaycastDetection.cs
1 parent add86a9 commit 370eaf2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

RaycastDetection.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//Inbora studio (clam all copyrights)2020-22 All scripts are code by Inbora Studio.
2+
//Devloped By Alok Khokhar for more information follow as on instagram @inbora.studio or ower webside.
3+
//https://inborastudio.wixsite.com/inborastudio
4+
5+
using UnityEngine;
6+
using UnityEngine.UI;
7+
8+
public class RaycastDetection : MonoBehaviour
9+
{
10+
Ray ray;
11+
RaycastHit raycastHit;
12+
Text textUI;
13+
14+
void Awake()
15+
{
16+
textUI = GameObject.FindObjectOfType<Text>();
17+
}
18+
19+
void Update()
20+
{
21+
ray = new Ray(transform.position, transform.forward);
22+
if(Physics.Raycast(ray, out raycastHit))
23+
{
24+
textUI.text = raycastHit.collider.gameObject.name;
25+
}
26+
else
27+
{
28+
textUI.text = "";
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)