質問編集履歴
2
enable = false と書けばコードは停止するはずだとご教授いただいたので、このコードを書いてもコードが停止しない現状を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -28,4 +28,156 @@
|
|
28
28
|
}
|
29
29
|
```
|
30
30
|
Dbug.Logは出力されていたので、このif文は動いています。
|
31
|
-
|
31
|
+
ですが、コードが停止しません。
|
32
|
+

|
33
|
+
|
34
|
+
enable = false と書くだけでもコードは停止すると教えていただいたのですが、試しに書いてみたところ停止しませんでした。
|
35
|
+
一応、停止させたいコードの全文を載せます。
|
36
|
+
Awake関数の中に、
|
37
|
+
enabled = false;
|
38
|
+
Invoke()
|
39
|
+
をどちらも書いています。
|
40
|
+
ですが、実行してみたところこの2つが実行された後もコードの処理が行われました。
|
41
|
+
このスクリプトファイルは、3D空間でキャラクターを操作するためのコードが書かれたファイルです。
|
42
|
+
Awake関数内で上記2つのコードが呼ばれ、スクリプトファイルが停止しているならばキャラクターの操作はできなくなるはずなのですが、キャラクターは全く問題なく操作できてしまいました。
|
43
|
+
```ここに言語を入力
|
44
|
+
using System.Collections;
|
45
|
+
using System.Collections.Generic;
|
46
|
+
using UnityEngine;
|
47
|
+
using UnityEngine.Events;
|
48
|
+
using Photon.Pun;
|
49
|
+
using Photon.Realtime;
|
50
|
+
|
51
|
+
namespace CSharpScript
|
52
|
+
{
|
53
|
+
|
54
|
+
public class UnkomanControl : MonoBehaviourPunCallbacks
|
55
|
+
{
|
56
|
+
Vector3 playerPos;
|
57
|
+
float InputX;
|
58
|
+
float InputZ;
|
59
|
+
Vector3 cameraForward;
|
60
|
+
Vector3 cameraRight;
|
61
|
+
Vector3 moveForward;
|
62
|
+
float runVelocity;
|
63
|
+
Vector3 translation;
|
64
|
+
Vector3 diff;
|
65
|
+
Quaternion Look;
|
66
|
+
Quaternion nageLook;
|
67
|
+
Animator anim;
|
68
|
+
Camera Camera;
|
69
|
+
Rigidbody rb;
|
70
|
+
Vector3 inputVector;
|
71
|
+
Vector3 normalVector;
|
72
|
+
Vector3 onPlane;
|
73
|
+
public Vector3 Translation { get; private set; }
|
74
|
+
public int unkomanActorNumber { get; private set; }
|
75
|
+
public int UnkomanInstanceID { get; private set; }
|
76
|
+
public UnityEvent invoke;
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
void Awake()
|
82
|
+
{
|
83
|
+
if (photonView.IsMine == true)
|
84
|
+
{
|
85
|
+
invoke.Invoke();
|
86
|
+
enabled = false;
|
87
|
+
Debug.Log("ああああああ");
|
88
|
+
}
|
89
|
+
|
90
|
+
playerPos = GetComponent<Transform>().position;
|
91
|
+
Camera = Camera.main;
|
92
|
+
anim = GetComponent<Animator>();
|
93
|
+
rb = GetComponent<Rigidbody>();
|
94
|
+
unkomanActorNumber = (int)photonView.InstantiationData[0];
|
95
|
+
UnkomanInstanceID = this.gameObject.GetInstanceID();
|
96
|
+
if (photonView.IsMine == true) Debug.Log(UnkomanInstanceID);
|
97
|
+
}
|
98
|
+
|
99
|
+
void OnCollisionStay(Collision collision)
|
100
|
+
{
|
101
|
+
normalVector = collision.contacts[0].normal;
|
102
|
+
}
|
103
|
+
|
104
|
+
bool hoge = true;
|
105
|
+
|
106
|
+
void Update()
|
107
|
+
{
|
108
|
+
if (!photonView.IsMine) return;
|
109
|
+
|
110
|
+
if (hoge == true)
|
111
|
+
{
|
112
|
+
Camera = Camera.main;
|
113
|
+
hoge = false;
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
InputX = Input.GetAxis("Horizontal");
|
121
|
+
InputZ = Input.GetAxis("Vertical");
|
122
|
+
|
123
|
+
|
124
|
+
cameraForward = Vector3.Scale(Camera.transform.forward, new Vector3(1, 0, 1)).normalized;
|
125
|
+
cameraRight = Vector3.Scale(Camera.transform.right, new Vector3(1, 0, 1)).normalized;
|
126
|
+
|
127
|
+
moveForward = cameraForward * InputZ + cameraRight * InputX;
|
128
|
+
|
129
|
+
runVelocity = 10.0f;
|
130
|
+
|
131
|
+
if (anim.GetCurrentAnimatorStateInfo(0).IsName("Untiburi") || anim.GetCurrentAnimatorStateInfo(0).IsName("GoldUntiburi"))
|
132
|
+
{
|
133
|
+
runVelocity = 0f;
|
134
|
+
}
|
135
|
+
if (Input.GetMouseButton(0))
|
136
|
+
{
|
137
|
+
runVelocity -= 7f;
|
138
|
+
}
|
139
|
+
if (anim.GetCurrentAnimatorStateInfo(0).IsName("UnkoNage") || anim.GetCurrentAnimatorStateInfo(0).IsName("GoldUnkoNage"))
|
140
|
+
{
|
141
|
+
runVelocity -= 7f;
|
142
|
+
}
|
143
|
+
|
144
|
+
translation = moveForward * runVelocity * Time.deltaTime;
|
145
|
+
translation = Vector3.ProjectOnPlane(translation, normalVector);
|
146
|
+
|
147
|
+
transform.Translate(translation, Space.World);
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
diff = new Vector3(transform.position.x - playerPos.x, 0f, transform.position.z - playerPos.z);
|
154
|
+
|
155
|
+
Look = Quaternion.LookRotation(diff, Vector3.up);
|
156
|
+
nageLook = Quaternion.LookRotation(cameraForward, Vector3.up);
|
157
|
+
|
158
|
+
if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Untiburi") && !anim.GetCurrentAnimatorStateInfo(0).IsName("UnkoNage") && !anim.GetCurrentAnimatorStateInfo(0).IsName("GoldUntiburi") && !anim.GetCurrentAnimatorStateInfo(0).IsName("GoldUnkoNage"))
|
159
|
+
{
|
160
|
+
if (InputX != 0f)
|
161
|
+
{
|
162
|
+
transform.rotation = Look;
|
163
|
+
}
|
164
|
+
if (InputZ != 0f)
|
165
|
+
{
|
166
|
+
transform.rotation = Look;
|
167
|
+
}
|
168
|
+
if (Input.GetMouseButton(0))
|
169
|
+
{
|
170
|
+
transform.rotation = nageLook;
|
171
|
+
}
|
172
|
+
if (Input.GetMouseButtonUp(0))
|
173
|
+
{
|
174
|
+
transform.rotation = nageLook;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
playerPos = transform.position;
|
179
|
+
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
```
|
1
回答を参考にして自分で試したことを追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,4 +8,24 @@
|
|
8
8
|
なので、スクリプト名.enabled = false と書いてみたのですがうまくいきませんでした。
|
9
9
|
GetComponent<自身のスクリプト>().enabled = false;のような処理を、GetComponentを使わずに書く方法はありませんか?
|
10
10
|
|
11
|
-
※単純に「enabled = false」と書くとその関数を停止させられますが、それだと一つの関数が停止するだけでスクリプトファイル全体が停止するわけではないので少し違います。
|
11
|
+
※単純に「enabled = false」と書くとその関数を停止させられますが、それだと一つの関数が停止するだけでスクリプトファイル全体が停止するわけではないので少し違います。
|
12
|
+
|
13
|
+
|
14
|
+
追記
|
15
|
+
教えていただいた回答を参考にしてInvokeを使ってコードを停止させる方法を試してみました。
|
16
|
+
```ここに言語を入力
|
17
|
+
public UnityEvent invoke;
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
void Awake()
|
23
|
+
{
|
24
|
+
if (photonView.IsMine == true)
|
25
|
+
{
|
26
|
+
invoke.Invoke();
|
27
|
+
Debug.Log("ああああああ");
|
28
|
+
}
|
29
|
+
```
|
30
|
+
Dbug.Logは出力されていたので、このif文は動いています。
|
31
|
+

|