teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

文法の改善

2021/08/03 05:33

投稿

hosituka
hosituka

スコア15

title CHANGED
File without changes
body CHANGED
@@ -11,10 +11,10 @@
11
11
  else
12
12
  {
13
13
  GetComponent<Renderer>().material.color -= new Color(0,0,0,0.01f);
14
- yield return new WaitForSeconds(0.05f);
14
+
15
15
 
16
16
  }
17
-
17
+ yield return new WaitForSeconds(0.05f);
18
18
  }
19
19
 
20
20
  Destroy(gameObject);

2

情報の付け足し

2021/08/03 05:33

投稿

hosituka
hosituka

スコア15

title CHANGED
File without changes
body CHANGED
@@ -1,16 +1,22 @@
1
1
  Unityで敵がfadeoutして消える仕組みを作るために最初にShaderのpropertyにcolorと言う名前があるかどうかをC#スクリプトのif文を使ってやりたいのですが下記のように試しにやってみたのですがダメでした何かやり方があった場合教えていただけるとありがたいです。
2
2
  ```C#
3
- if( gameObject.GetComponent<Renderer>().material.color == null)
3
+ private IEnumerator teki_fadeout()
4
4
  {
5
+ for (float a = 1; a == 0; a-=0.01f)
6
+ {
7
+ if( gameObject.GetComponent<Renderer>().material.color == null)
8
+ {
5
- //colorがなかった場合の処理
9
+ //colorがなかった場合の処理
10
+ }
11
+ else
12
+ {
13
+ GetComponent<Renderer>().material.color -= new Color(0,0,0,0.01f);
14
+ yield return new WaitForSeconds(0.05f);
15
+
16
+ }
17
+
18
+ }
19
+
20
+ Destroy(gameObject);
6
21
  }
7
- else
8
- {
9
- for (float a = 1; a == 0; a-=0.01f)
10
- {
11
-
12
- GetComponent<Renderer>().material.color -= new Color(0,0,0,0.01f);
13
- yield return new WaitForSeconds(0.05f);
14
- }
15
- }
16
22
  ```

1

fadeoutする部分追加

2021/08/03 05:32

投稿

hosituka
hosituka

スコア15

title CHANGED
File without changes
body CHANGED
@@ -6,6 +6,11 @@
6
6
  }
7
7
  else
8
8
  {
9
- //colorがあった場合の処理
9
+ for (float a = 1; a == 0; a-=0.01f)
10
+ {
11
+
12
+ GetComponent<Renderer>().material.color -= new Color(0,0,0,0.01f);
13
+ yield return new WaitForSeconds(0.05f);
14
+ }
10
15
  }
11
16
  ```