私は、オブジェクトを連続的に生成し、生成されたすべてのオブジェクトにスクリプトを添付するスクリプトを作成しようとしています。 3秒後に添付されたスクリプトを作成し、オブジェクトのマテリアルを変更して、ボックスコライダーを追加します。私の問題は材料にあります。オブジェクトはランダムに生成されているので、マテリアル変数を設定する方法はわかりません。Unity - ゲームオブジェクトにマテリアルを追加
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Astroid : MonoBehaviour {
//I need to be able to set this variable to a material
public Material mat;
// Use this for initialization
void Start() {
this.GetComponent<SphereCollider>().enabled = false;
StartCoroutine("Change");
}
// Update is called once per frame
void Update() {
}
IEnumerator Change(){
yield return new WaitForSeconds (3);
this.GetComponent<SphereCollider>().enabled = true;
this.GetComponent<Renderer>().material = mat;
}
}
この答えは間違っています。 [Unity Documentation](https://docs.unity3d.com/ScriptReference/Resources.Load.html)によると、拡張は省略されなければならない。 –