Script Warp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Warp : MonoBehaviour {
public bool waprCheck = false;
public Vector3 vector3Point;
private void Update()
{
if (waprCheck)
{
WarpMethod(vector3Point);
waprCheck = false;
}
}
public void WarpMethod(Vector3 warpPoint)
{
transform.position = warpPoint;
}
}
| cs |
응용으로 VR이나 특정 포인트를 가르키는 위치로 워프할 수 있다.
응용 스크립트
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(LineRenderer))] // LineRenderer 컴포넌트추가
public class ShotRendererAndRay : MonoBehaviour {
Ray shootRay; // 레이
RaycastHit shootHit; // 레이케스트
LineRenderer lineRenderer; // 라인렌더러
Warp warp;
Vector3 warpPoint;
public float range = 100f; // 범위
public bool trigger = false; // 이벤트 트리거
public bool isRayShoot = false;
public bool warpCheck = false;
public bool warpStart = false;
private void Start()
{
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.enabled = false;
warp = GetComponent<Warp>();
}
void Update()
{
if(trigger)
StartShoot();
else
StopShoot();
if (isRayShoot)
Shoot();
if (warpCheck)
{
warp.WarpMethod(warpPoint);
warpCheck = false;
}
}
// Start.
void StartShoot()
{
lineRenderer.enabled = true;
lineRenderer.positionCount = 2;
isRayShoot = true;
}
// End.
void StopShoot()
{
isRayShoot = false;
lineRenderer.positionCount = 0;
lineRenderer.enabled = false;
}
// LineRenderer, Ray - Shoot
void Shoot()
{
lineRenderer.SetPosition(0, transform.position); // lineRenderer 0번째 object position 설정
shootRay.origin = transform.position;
shootRay.direction = transform.forward;
// is ray target
if (Physics.Raycast(shootRay, out shootHit))
{
Vector3 v3Pos = shootRay.GetPoint(shootHit.distance * 0.995f);
lineRenderer.SetPosition(1, v3Pos); // lineRenderer 1번째 target position 설정
if(warpStart)
{
warpPoint = v3Pos;
warpCheck = true;
warpStart = false;
}
}
// is ray target null
else
{
float distance = 2;
Vector3 forward = transform.forward * distance + transform.position;
lineRenderer.SetPosition(1, forward); // lineRenderer 1번째 설정
if (warpStart)
{
warpPoint = forward;
warpCheck = true;
warpStart = false;
}
// object's forward position + object position
}
}
}
| cs |
댓글
댓글 쓰기