質問編集履歴

5

スクリプトを再び変更

2018/07/01 09:10

投稿

yuukuriuttto
yuukuriuttto

スコア24

test CHANGED
File without changes
test CHANGED
@@ -29,6 +29,8 @@
29
29
 
30
30
 
31
31
  ```c#
32
+
33
+
32
34
 
33
35
  using System.Collections;
34
36
 
@@ -110,8 +112,6 @@
110
112
 
111
113
  {
112
114
 
113
-
114
-
115
115
  Debug.Log("move");
116
116
 
117
117
  ray = Camera.main.ScreenPointToRay(Input.mousePosition);
@@ -126,37 +126,29 @@
126
126
 
127
127
  Debug.Log(hit.point);//デバッグログにクリックした場所を出す
128
128
 
129
- const float NearDistance = 0.01f;
130
-
131
- if(Vector3.Distance(targetPosition.position ,hit.point) < NearDistance)
132
-
133
- {
134
-
135
- targetPosition.position = hit.point;
136
-
137
- arrived = true;
138
-
139
- Debug.Log("arrived");
140
-
141
- this.animator.SetTrigger(Trigger_isWait);
142
-
143
- }
144
-
145
-
146
-
147
129
  if(hit.collider.gameObject)
148
130
 
149
131
  {
150
132
 
151
133
  agent.SetDestination(hit.point);
152
134
 
153
- //if(hit.collider.gameObject.CompareTag(Terraintag))
154
135
 
155
- //{
156
136
 
157
- // agent.SetDestination(hit.point);
137
+ const float NearDistance = 0.4f;
158
138
 
139
+ if(Vector3.Distance(targetPosition.position ,hit.point) < NearDistance)
140
+
141
+ {
142
+
143
+ targetPosition.position = hit.point;
144
+
159
- //}
145
+ arrived = true;
146
+
147
+ Debug.Log("arrived");
148
+
149
+ this.animator.SetTrigger(Trigger_isWait);
150
+
151
+ }
160
152
 
161
153
  }
162
154
 
@@ -169,8 +161,6 @@
169
161
  }
170
162
 
171
163
  }
172
-
173
-
174
164
 
175
165
 
176
166
 

4

スクリプトを変更

2018/07/01 09:10

投稿

yuukuriuttto
yuukuriuttto

スコア24

test CHANGED
File without changes
test CHANGED
@@ -42,11 +42,9 @@
42
42
 
43
43
 
44
44
 
45
- public class Move : MonoBehaviour
45
+ public class Move: MonoBehaviour {
46
-
47
- {
46
+
48
-
49
- public Transform targetPosition; //移動する位置
47
+ public Transform targetPosition; //移動する位置
50
48
 
51
49
  public GameObject DestroyButton;
52
50
 
@@ -66,6 +64,8 @@
66
64
 
67
65
 
68
66
 
67
+
68
+
69
69
  // 到着フラグ
70
70
 
71
71
  private bool arrived;
@@ -78,7 +78,7 @@
78
78
 
79
79
  // Use this for initialization
80
80
 
81
- void Start()
81
+ void Start ()
82
82
 
83
83
  {
84
84
 
@@ -102,61 +102,61 @@
102
102
 
103
103
  // Update is called once per frame
104
104
 
105
- void Update()
105
+ void Update ()
106
106
 
107
107
  {
108
108
 
109
- if (Input.GetMouseButton(0))
109
+ if(Input.GetMouseButton(0))
110
110
 
111
111
  {
112
112
 
113
+
114
+
115
+ Debug.Log("move");
116
+
117
+ ray = Camera.main.ScreenPointToRay(Input.mousePosition);
118
+
113
- if (!arrived)
119
+ if(!arrived)
114
120
 
115
121
  {
116
122
 
117
- Debug.Log("move");
118
-
119
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
120
-
121
- if (Physics.Raycast(ray, out hit, 100))
123
+ if(Physics.Raycast(ray ,out hit ,100))
122
124
 
123
125
  {
124
126
 
125
-
126
-
127
-
128
-
129
- Debug.Log(hit.point);//デバッグログにした場所を出す
127
+ Debug.Log(hit.point);//デバッグログにクリした場所を出す
130
-
128
+
131
- if (hit.collider.gameObject)
129
+ const float NearDistance = 0.01f;
130
+
131
+ if(Vector3.Distance(targetPosition.position ,hit.point) < NearDistance)
132
132
 
133
133
  {
134
134
 
135
+ targetPosition.position = hit.point;
136
+
137
+ arrived = true;
138
+
139
+ Debug.Log("arrived");
140
+
141
+ this.animator.SetTrigger(Trigger_isWait);
142
+
143
+ }
144
+
145
+
146
+
147
+ if(hit.collider.gameObject)
148
+
149
+ {
150
+
135
151
  agent.SetDestination(hit.point);
136
152
 
137
-
138
-
139
- if (hit.collider.gameObject.CompareTag(Terraintag))
153
+ //if(hit.collider.gameObject.CompareTag(Terraintag))
140
-
154
+
141
- {
155
+ //{
142
-
156
+
143
- agent.SetDestination(hit.point);
157
+ // agent.SetDestination(hit.point);
144
-
145
- }
158
+
146
-
147
-
148
-
149
- if (Vector3.Distance(targetPosition.position, hit.point) < 0.5f)
150
-
151
- {
152
-
153
- Debug.Log("arrived");
154
-
155
- arrived = true;
159
+ //}
156
-
157
- this.animator.SetTrigger(Trigger_isWait);
158
-
159
- }
160
160
 
161
161
  }
162
162
 

3

発生している問題の個所を変更

2018/07/01 05:42

投稿

yuukuriuttto
yuukuriuttto

スコア24

test CHANGED
File without changes
test CHANGED
@@ -16,11 +16,9 @@
16
16
 
17
17
  ```
18
18
 
19
- ナビュを使クリックした所にRayを飛ばしてプレイヤーを移動させている
19
+ 処理は合っているが、今の構文だと待機するアニョンのif文まで行かなと感じました
20
-
21
-
22
-
20
+
23
- のですが、Vector3.Distance使用したコードにたがUnassignedReferenceExceptionエラーが出て進まず
21
+ どこを変えればいいでょうか?
24
22
 
25
23
  ```
26
24
 
@@ -128,7 +126,7 @@
128
126
 
129
127
 
130
128
 
131
- Debug.Log("targetPosition");//デバッグログにヒットした場所を出す
129
+ Debug.Log(hit.point);//デバッグログにヒットした場所を出す
132
130
 
133
131
  if (hit.collider.gameObject)
134
132
 

2

発生している問題のところを変更

2018/07/01 05:02

投稿

yuukuriuttto
yuukuriuttto

スコア24

test CHANGED
File without changes
test CHANGED
@@ -20,11 +20,7 @@
20
20
 
21
21
 
22
22
 
23
- のですが、プレイヤーが移動したRayを飛ばした場所と若干のズレ起き
23
+ のですが、Vector3.Distanceを使用したコード変更したがUnassignedReferenceExceptionエラーが出進まず
24
-
25
-
26
-
27
- まい、待機状態にならない
28
24
 
29
25
  ```
30
26
 

1

Vector3.Distanceを使用したコードを追加しました

2018/06/28 18:35

投稿

yuukuriuttto
yuukuriuttto

スコア24

test CHANGED
File without changes
test CHANGED
@@ -52,7 +52,7 @@
52
52
 
53
53
  {
54
54
 
55
- private Vector3 targetPosition; //移動する位置
55
+ public Transform targetPosition; //移動する位置
56
56
 
57
57
  public GameObject DestroyButton;
58
58
 
@@ -70,6 +70,12 @@
70
70
 
71
71
  private Animator animator;
72
72
 
73
+
74
+
75
+ // 到着フラグ
76
+
77
+ private bool arrived;
78
+
73
79
  static Canvas _canvas;
74
80
 
75
81
  private const string Trigger_isWait = "is_Wait";
@@ -94,6 +100,8 @@
94
100
 
95
101
  animator = GetComponent<Animator>();
96
102
 
103
+ arrived = false;
104
+
97
105
  }
98
106
 
99
107
 
@@ -106,42 +114,62 @@
106
114
 
107
115
  if (Input.GetMouseButton(0))
108
116
 
109
- {
117
+ {
110
-
118
+
111
- Debug.Log("move");
119
+ if (!arrived)
112
-
113
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
114
-
115
- if (Physics.Raycast(ray, out hit, 100))
116
120
 
117
121
  {
118
122
 
119
- targetPosition = hit.point;
123
+ Debug.Log("move");
124
+
120
-
125
+ ray = Camera.main.ScreenPointToRay(Input.mousePosition);
126
+
121
-
127
+ if (Physics.Raycast(ray, out hit, 100))
128
+
122
-
129
+ {
130
+
131
+
132
+
133
+
134
+
123
- Debug.Log(targetPosition);//デバッグログにヒットした場所を出す
135
+ Debug.Log("targetPosition");//デバッグログにヒットした場所を出す
136
+
124
-
137
+ if (hit.collider.gameObject)
138
+
125
-
139
+ {
140
+
126
-
141
+ agent.SetDestination(hit.point);
142
+
143
+
144
+
127
- if (hit.collider.gameObject.CompareTag(Terraintag))
145
+ if (hit.collider.gameObject.CompareTag(Terraintag))
128
-
146
+
129
- {
147
+ {
130
-
148
+
131
- agent.SetDestination (targetPosition);
149
+ agent.SetDestination(hit.point);
132
-
150
+
133
- }
151
+ }
152
+
153
+
154
+
155
+ if (Vector3.Distance(targetPosition.position, hit.point) < 0.5f)
156
+
157
+ {
158
+
159
+ Debug.Log("arrived");
160
+
161
+ arrived = true;
162
+
163
+ this.animator.SetTrigger(Trigger_isWait);
164
+
165
+ }
166
+
167
+ }
168
+
169
+ }
134
170
 
135
171
  }
136
172
 
137
- if (transform.position == targetPosition)
138
-
139
- {
140
-
141
- this.animator.SetTrigger(Trigger_isWait);
142
-
143
- }
144
-
145
173
  }
146
174
 
147
175
  }
@@ -152,8 +180,6 @@
152
180
 
153
181
 
154
182
 
155
-
156
-
157
183
  ```
158
184
 
159
185
  ### 試したこと