-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRaycastExample.cs
More file actions
37 lines (27 loc) · 847 Bytes
/
RaycastExample.cs
File metadata and controls
37 lines (27 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using UnityEngine;
using System.Collections;
public class RayCastExample : MonoBehaviour
{
void Start ()
{
//For initializations
}
// Update is called once per frame
void Update()
{
var up = transform.TransformDirection(Vector3.up);
// note the use of var as the type. This is because in c# you
// can have lamda functions which open up the use of untyped variables
// these variables can only live inside a function.
RaycastHit hit;
Debug.DrawRay(transform.position, -up * 2, Color.green);
if (Physics.Raycast(transform.position, -up, out hit, 2))
{
Debug.Log("Beep Beep");
if (hit.collider.gameObject.name == "floor")
{
Destroy(GetComponent("Rigidbody"));
}
}
}
}