Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity detect object with raycast

 using UnityEngine;
 
 public class Raycaster : MonoBehaviour {
     void Update() {
         RaycastHit hit;
         if (Physics.Raycast(transform.position, -Vector3.up, out hit))
             hit.transform.SendMessage ("HitByRay");
         
     }
 }
 
 //The object would have a script like this:

 using UnityEngine;
 
 public class ObjectHit : MonoBehaviour {
     void HitByRay () {
         Debug.Log ("I was hit by a Ray");
     }
 }
Comment

PREVIOUS NEXT
Code Example
Csharp :: avoid autocomplete input text asp.net 
Csharp :: How can I cast string to enum? 
Csharp :: c# object initialization can be simplified 
Csharp :: equivalent to T extends TT in c# 
Csharp :: c# get path without filename 
Csharp :: convert object to xml c# example code 
Csharp :: valid url in .net 
Csharp :: c# read next int Like Java 
Csharp :: instantiate scale object 
Csharp :: make an object disappear from a c# script unity 
Csharp :: c# list get element from end 
Csharp :: unity mouse movement 
Csharp :: emboss button in android app 
Csharp :: print in c# unity 
Csharp :: How to read a XML on C# 
Csharp :: c# @ before string 
Csharp :: how to make an object jump in unity 
Csharp :: unity hide in inspector 
Csharp :: How can you learn C# on your own 
Csharp :: c# datetimepicker set weeks after today 
Csharp :: C# .NET Core linq Distinct 
Csharp :: invert string c# 
Csharp :: unity clamp rotation 
Csharp :: how to start cmd in c# 
Csharp :: unity check if a animator parameter trigger is activated 
Csharp :: how to display an image url in c# picturebox 
Csharp :: c# create dynamic object 
Csharp :: how to deselect a button through code unity 
Csharp :: how to move a gameobject to another object 
Csharp :: c# string to variable name 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =