Hi guys, how can I change colour of a node when the collision happens?
Are you talking about the color of the node itself or the color of the node within the editor?
I mean changing the node’s color in script
That depends, it’s not related to the Node, it’s related to the Renderer Component, like Sprite
or MeshRenderer
's Material setting
this.node.color = cc.Color.GREEN;
the ‘cc’ is deprecated
for example, I have a main node containing the snake’s head and body. I want to change the colour of the head when the snake bites its own.
If it’s 3d, you will need to make a variant material which has different color for hit. When it’s hit, do something like the following
headNode.getComponent(MeshRenderer).setMaterialInstance(hitMaterial, 0);
If it’s a sprite, then
headNode.getComponent(Sprite).color = new Color(255, 0, 0, 255); // red
2 Likes
Thanks