-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDishonoredSpell.cs
38 lines (32 loc) · 991 Bytes
/
DishonoredSpell.cs
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
38
using UnityEngine;
using System.Collections;
public class DishonoredSpell : MonoBehaviour {
private RaycastHit lastRaycastHit;
public AudioClip audioClip;
public float range = 1000;
private GameObject GetLookedAtObject()
{
Vector3 origin = transform.position;
Vector3 direction = Camera.main.transform.forward;
if (Physics.Raycast(origin, direction, out lastRaycastHit, range))
{
return lastRaycastHit.collider.gameObject;
}
else
{
return null;
}
}
private void TeleportToLookAt()
{
transform.position = lastRaycastHit.point + lastRaycastHit.normal * 1.5f;
if (audioClip != null)
AudioSource.PlayClipAtPoint(audioClip, transform.position);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
if (GetLookedAtObject() != null)
TeleportToLookAt();
}
}