playMode
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMYcVWCnOY4HCpcu95RfvM-70ipkCVbjuQEsE7SdAT9mm9aNjSovxkwO7XwdqGGVIfF9Fbxp0A_M56zIZxFlx5p6YpWiE_7pBQ81hmcQ5_JGuW_Y0RiDmkkn5-F5MOL517kLjvf8tSAxE/s640/0.PNG)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXrCOD8oPKn9j6zIXGtygQ7wmawQA51hpvbMfl5BpRDsYzSR8F5tlGjsil_1Pmu_O9t0xCUUoWboEVVxe89mjRfhgAPPnWakKAFrxt5FdUEWZKleuvhut5QiaPdgSERMfXs7gLN3P7bXU/s640/1.PNG)
---------------------------------------------
target
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidB-XYgdQSGarNCwEpw-XuqFQRubN0ZTpOHvDL1DToqXg83-EZuY1SBvoNCLbsnoD8WIGsTbV9n8CxW6MhzpqbG9aEA7YUd_MbS7Xw-LVgMA2Bsaj7JKQbKxa7oL-7WNben1bNonoVN7Y/s640/Destination.PNG)
arrow - Set tag
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYGZYYp90jjjGMrNWx0vl6FHq-21U76MXypcWeiVdp9zAegNXWFCQsqkHZ0k73E4YnCctmr47gIHr1ykgMy42bz5czqfk1FKLxqv1i4z6ThbzqkirS_8Dc8azTFkOvagewweg8n_oy22Q/s640/arrow.PNG)
pathPoint - set tag
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCszlmMOBAZxPJkrkIzqrMOfX1HJ9SwAh5DnSswNDNe4yvhfLprsubge6RnkmLgS1oLXvH7J6-_bPSWRExtAvQ6k42e0zYAVkr358rDh-3g27TJI1OOZ299nEkfK2UCus6KdsOVCs_Cl0/s640/pathPoint.PNG)
Backgtound - Set Navigation static
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnX7sBbsY9IXQ1KXM-gwSm1ZJXxsMfzaQC3UJY1KDZEYvdJAg2aAy6rJDDROt56hehQ2rBO8_e0q0wBjXB0GHiRDpELOGLq24OazUUsMveOjPI2dBQ54OXNVf-xKMc9oteTf3NNqIJVdw/s640/background.PNG)
Bake
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrkAXboy1QVwr6GV43gWdNnq1kL5zB5dZacCwwLyGAvzOEHQN5bO7HeHFMaFU-gJaX0jOrkXsFgJG-dcj9uBvvNopcA-O4NnwEtnmtHEX4WFUu1lFj1lOQCohU8gULAbLWfHkIgcNwIBs/s640/SetNav.PNG)
Player Setting
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRe00-bMpRRHW7GQoNccZaLSZUZ6ALBBuH8Ef2HL65N1vvQJc0X7Xd8nc40X32xAVVCfLspPqHvbrK2B_mAjIre8fwSQqSZdEHYKwRE6SnfigSR5D7aDc0KmBtyb8ZI11BtEJbyPyoagc/s640/PlayerSetting.PNG)
---------------------------------------------
target
arrow - Set tag
pathPoint - set tag
Backgtound - Set Navigation static
Bake
Player Setting
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class MoveLine : MonoBehaviour {
NavMeshAgent nav;
public Transform target; // target Object Transfrom
public GameObject arrowPrefab; // arrowPrefab
public GameObject pathPointPrefab; // see meshPoint Path
public int distanceOfEachObject;
public bool completePath = false;
public bool temp = false;
private void Start()
{
nav = GetComponent<NavMeshAgent>();
nav.isStopped = true;
}
void Update()
{
if (temp)
{
GameObject[] delObj = GameObject.FindGameObjectsWithTag("arrow");
foreach (GameObject obj in delObj)
Destroy(obj);
completePath = false;
temp = false;
}
OnDrawDirection(target);
}
void OnDrawDirection(Transform obj)
{
Vector3 posA, posB;
if (nav == null || nav.path == null)
return;
nav.SetDestination(obj.position); // Destination
// issue : 첫 도착지를 설정할때 nav.path.Length가 1이다.
var path = nav.path;
if (path.corners.Length < 2)
return;
if (completePath)
return;
// Create Objects
for (int i = 0; i < path.corners.Length-1; i++)
{
posA = path.corners[i];
posB = path.corners[i + 1];
float vectorDis = Vector3.Distance(posA, posB); // distance A to B vector
float repeatCount = vectorDis/ distanceOfEachObject;
float linearInterpolation = 1 / repeatCount; // 선형보간
// if vectorDis<1, create a object. center From A and B.
if (repeatCount < 1)
{
repeatCount = 1;
linearInterpolation = 0.5f;
}
GameObject pathPos = Instantiate(pathPointPrefab);
pathPos.transform.position = path.corners[i];
pathPos.transform.SetParent(GameObject.Find("Nods").GetComponent<Transform>());
// create object.
for (int j = 1; j <= (int)repeatCount; j++)
{
Vector3 position = Vector3.Lerp(posA, posB, j * linearInterpolation); // position Vector
GameObject arrowPosition = Instantiate(arrowPrefab);
arrowPosition.transform.position = position; // Set position
arrowPosition.transform.LookAt(posB); // Set direction
arrowPosition.transform.eulerAngles = new Vector3(90, arrowPosition.transform.eulerAngles.y); // Set angle
arrowPosition.transform.SetParent(GameObject.Find("Nods").GetComponent<Transform>()); // Set hierarchy
}
}
completePath = true; // Done
}
}
| cs |
댓글
댓글 쓰기