如何正确更改 Godot3 中的网格颜色?
extends MeshInstance
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
var i=0
export(Color) var new_color = Color(1, 1, 1, 1)
func _ready():
var n = self
var mat=n.get_mesh().surface_get_material(0)
var mat2 = SpatialMaterial.new()
mat2.albedo_color = Color(0.8, 0.0, 0.0)
self.get_mesh().surface_set_material(0,mat2)
set_process(true)
# Called every time the node is added to the scene.
# Initialization here
func _process(delta):
randomize()
var mat2 = SpatialMaterial.new()
mat2.albedo_color = Color8(255, 0, 0)
var i = rand_range(0.0,100.0)
if i>50.0:
self.get_mesh().surface_set_material(0,mat2)
i=0
else:
mat2.albedo_color = Color8(0, 0, 255)
self.get_mesh().surface_set_material(0,mat2)
我尝试了这个简单的代码来改变 godot3 引擎中的网格颜色。这个想法可能有助于改变汽车的阶梯灯颜色,例如在某些游戏中。