4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Unity】material変更時にはまったこと

Posted at

あまりに基礎的なことを忘れていたので。

問題

モデルのマテリアルをスクリプトから変更したが反映されない。

    Material m = dragon.GetComponent<Renderer>().material;
    m = Resources.Load<Material>("001_ChangeColor/001_ChangeColorMaterial");

原因

マテリアルの参照を直に書き換えても、レンダラーからマテリアルへの参照は変更されないから。
オブジェクトを変更しようとした場合、一つ上のオブジェクトからたどる必要がある。

   Renderer r = dragon.GetComponent<Renderer>();
   r.material = Resources.Load<Material>("001_ChangeColor/001_ChangeColorMaterial");
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?