What i am trying to accomplish is every-time my player touches a cube it changes the color of the cube that is touched.
In this case the color would be red.
The Problem i am having is when trying to use “gameObject.Find()”
when i use this it finds ONE game object and turns the color to red.
Here is the code:
` function OnCollisionEnter(theCollision : Collision) { Debug.Log("Hit"); if(theCollision.gameObject.name == "Cube_Neut") { var theCube = gameObject.Find("Cube"); theCube.transform.renderer.material.color = Color.red; Debug.Log("Changed Color"); } } `
The thing is that my “gameObject” was imported and has two children because there is a rim (if you want to call it that) around the corners of the cube and the regular cube itself.
So in the Hierarchy it looks like this:
` Map_1 (Map_1 representing the level as a whole) -Cube_Neut (Child of "Map_1") -Cube (This is the part i want to turn Red. Child of "Cube_Neut") -Cube_006 (This is the black rim of the cube that i want to keep the same. Child of "Cube_Neut") `
I am trying to find a better way of doing this so that is why i am here.
Any Help is Appreciated