私はUnityのためのC#を使用しています、私は2つのオブジェクト(スクリプトファイルを有するものである現在のもの、と私はその材料を変更したい他のものを)持っている、これは私のコードです:Unityで他のオブジェクトを制御するには?
public class PlayerController : MonoBehaviour {
public Material[] material;
Renderer rend;
public float speed;
private Rigidbody rb;
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
rend.sharedMaterial = material [0];
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{ // Here is the problem, it will change the color of the current object not the other one
rend.sharedMaterial = material [1];
}
}
}
助けてください! ありがとうございました
ありがとうございます。 –