Unity3d Unity Spriterender在脚本中设置材质
我只想在脚本中设置精灵渲染器的材质。我该怎么做?Unity3d Unity Spriterender在脚本中设置材质,unity3d,components,sprite,Unity3d,Components,Sprite,我只想在脚本中设置精灵渲染器的材质。我该怎么做? 因此,我想在代码中设置精灵渲染器的材质,但它不起作用,我也不知道为什么。通过拖放精灵渲染器和要切换到的材质,可以在检查器中设置对象/新材质 编辑: 公共游戏对象; 公共材料新材料; //... object.GetComponent().material=newMaterial; 但在精灵渲染器中,有一个包含材质的字段 public GameObject object; public Material newMaterial; //... obj
因此,我想在代码中设置精灵渲染器的材质,但它不起作用,我也不知道为什么。通过拖放精灵渲染器和要切换到的材质,可以在检查器中设置对象/新材质 编辑:
公共游戏对象;
公共材料新材料;
//...
object.GetComponent().material=newMaterial;
但在精灵渲染器中,有一个包含材质的字段
public GameObject object;
public Material newMaterial;
//...
object.GetComponent<SpriteRenderer>().material = newMaterial;