Change color of a cube when touched by a ray unity

0

Good afternoon, I'm doing an exercise where I have a "beam" created with Line Renderer and I want the block to change color when the beam touches a block. As shown in the picture the lightning comes out of the red block, but I want the white block to change. Thanks

The code I am using is the one that appears in the second image, but what it does is change the color of the cube with "eye" and not the white cube

    
asked by TheFPiriz 24.10.2017 в 17:49
source

1 answer

1

I guess the previous code is in the red block, if so, you must modify the line in if as follows:

collider.gameObject.GetComponent<Renderer>().material.color = Color.red;

in this way you are changing the color of the object with which you collide, otherwise you were changing the object in which the script is located.

    
answered by 09.11.2017 в 19:00