スクリプト中で通常のRendererとTrail Rendererのmaterialをそれぞれ別に変更したいのですが、現状のプログラムだとTrail Rendererのマテリアルも通常Rendererと同じになってしまいます。(Trail RendererのマテリアルもFX_Maskになってしまい、Trail(マテリアル)が適用されない)
Trail Rendererのマテリアルを指定して変更するプログラムはどのように書けばよいのでしょうか。
using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(Rigidbody))] public class BoiceMove : MonoBehaviour { private Rigidbody physics = null; public Material[] _material; // 割り当てるマテリアル. GameObject fire,thuder,freese; public void Awake() { this.physics = this.GetComponent<Rigidbody>(); } public void FlipThunder() { this.GetComponent<Renderer>().material = _material[0]; GameObject prefab1 = (GameObject)Resources.Load("ErekiBall2"); thuder = Instantiate(prefab1, this.transform.position, Quaternion.identity); //GetComponent<TrailRenderer>().material = _material[0]; StartCoroutine(Gogo()); Destroy(thuder, 1f); } public void FlipFire() { this.GetComponent<Renderer>().material = _material[1]; GameObject prefab2 = (GameObject)Resources.Load("FlamesParticleEffect"); fire = Instantiate(prefab2, this.transform.position, Quaternion.identity); //GetComponent<TrailRenderer>().material = _material[1]; StartCoroutine(Gogo()); Destroy(fire, 1f); } public void FlipFreese() { this.GetComponent<Renderer>().material = _material[2]; GameObject prefab3 = (GameObject)Resources.Load("Smoke"); freese = Instantiate(prefab3, this.transform.position, Quaternion.identity); //GetComponent<TrailRenderer>().material = _material[2]; StartCoroutine(Gogo()); Destroy(freese, 1f); } IEnumerator Gogo() { yield return new WaitForSeconds(1f); GetComponent<TrailRenderer>().enabled = true; this.physics.AddForce(new Vector3(0, 0, 1000f)); } }
this.GetComponent<Renderer>().material = _material[0];
GetComponent<TrailRenderer>().material = _material[0];
そもそもどちらも同じマテリアルを指定しているように見えるのですが。
そこの部分の書き方がわからなくて、Boice Moveのマテリアルが配列番号0,1,2、Trail Rendererのマテリアルが3,4,5かと思ったのですが、そう書くと配列外エラーが発生してしまいました。
IndexOutOfRangeException: Index was outside the bounds of the array.
説明しづらいので、BoiceMoveのスクリプト全文を掲載してもらえますか?
追加しました
回答1件
あなたの回答
tips
プレビュー