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

質問編集履歴

2

書式

2019/08/29 05:45

投稿

Warthen_6500
Warthen_6500

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,7 @@
1
1
  スクリプト中で通常のRendererとTrail Rendererのmaterialをそれぞれ別に変更したいのですが、現状のプログラムだとTrail Rendererのマテリアルも通常Rendererと同じになってしまいます。(Trail RendererのマテリアルもFX_Maskになってしまい、Trail(マテリアル)が適用されない)
2
2
 
3
3
  Trail Rendererのマテリアルを指定して変更するプログラムはどのように書けばよいのでしょうか。
4
+ ```
4
5
  using System.Collections;
5
6
  using System.Collections.Generic;
6
7
  using UnityEngine;

1

BoiceMove全文

2019/08/29 05:45

投稿

Warthen_6500
Warthen_6500

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,22 +1,61 @@
1
1
  スクリプト中で通常のRendererとTrail Rendererのmaterialをそれぞれ別に変更したいのですが、現状のプログラムだとTrail Rendererのマテリアルも通常Rendererと同じになってしまいます。(Trail RendererのマテリアルもFX_Maskになってしまい、Trail(マテリアル)が適用されない)
2
2
 
3
3
  Trail Rendererのマテリアルを指定して変更するプログラムはどのように書けばよいのでしょうか。
4
+ using System.Collections;
5
+ using System.Collections.Generic;
6
+ using UnityEngine;
4
7
 
8
+ [RequireComponent(typeof(Rigidbody))]
5
- ```BoiceMove
9
+ public class BoiceMove : MonoBehaviour {
10
+
11
+ private Rigidbody physics = null;
12
+ public Material[] _material; // 割り当てるマテリアル.
13
+ GameObject fire,thuder,freese;
14
+
6
- public void FlipThunder()
15
+ public void Awake()
7
16
  {
17
+ this.physics = this.GetComponent<Rigidbody>();
18
+ }
19
+
20
+
21
+
22
+ public void FlipThunder()
23
+ {
8
24
  this.GetComponent<Renderer>().material = _material[0];
9
- GetComponent<TrailRenderer>().enabled = true;
25
+ GameObject prefab1 = (GameObject)Resources.Load("ErekiBall2");
26
+ thuder = Instantiate(prefab1, this.transform.position, Quaternion.identity);
10
- GetComponent<TrailRenderer>().material = _material[0];
27
+ //GetComponent<TrailRenderer>().material = _material[0];
28
+ StartCoroutine(Gogo());
11
- this.physics.AddForce(new Vector3(0, 0, 1000f));
29
+ Destroy(thuder, 1f);
12
30
  }
13
31
 
14
- public void FlipFire()
32
+ public void FlipFire()
15
33
  {
16
34
  this.GetComponent<Renderer>().material = _material[1];
35
+ GameObject prefab2 = (GameObject)Resources.Load("FlamesParticleEffect");
36
+ fire = Instantiate(prefab2, this.transform.position, Quaternion.identity);
37
+ //GetComponent<TrailRenderer>().material = _material[1];
38
+ StartCoroutine(Gogo());
39
+ Destroy(fire, 1f);
40
+ }
41
+
42
+ public void FlipFreese()
43
+ {
44
+ this.GetComponent<Renderer>().material = _material[2];
45
+ GameObject prefab3 = (GameObject)Resources.Load("Smoke");
46
+ freese = Instantiate(prefab3, this.transform.position, Quaternion.identity);
47
+ //GetComponent<TrailRenderer>().material = _material[2];
48
+ StartCoroutine(Gogo());
49
+ Destroy(freese, 1f);
50
+ }
51
+
52
+ IEnumerator Gogo()
53
+ {
54
+ yield return new WaitForSeconds(1f);
17
55
  GetComponent<TrailRenderer>().enabled = true;
18
- GetComponent<TrailRenderer>().material = _material[1];
19
56
  this.physics.AddForce(new Vector3(0, 0, 1000f));
20
57
  }
58
+
59
+ }
21
60
  ```
22
61
  ![InspectorのMesh](0371f4d5a578a9d1f4f78ee6c588b16c.png)