void ColorTankMouseUp(GameObjectAnimator obj) { // Changes tank color to white Renderer renderer = obj.GetComponentInChildren <Renderer>(); renderer.sharedMaterial.color = Color.yellow; }
void RestoreTankColor(GameObjectAnimator obj) { // Restores original tank color Renderer renderer = obj.GetComponentInChildren <Renderer>(); Color tankColor = obj.attrib["color"]; // get back the original color from attribute bag renderer.sharedMaterial.color = tankColor; }
void ColorTankHover(GameObjectAnimator obj) { // Changes tank color - but first we store original color inside its attribute bag Renderer renderer = obj.GetComponentInChildren <Renderer>(); obj.attrib["color"] = renderer.sharedMaterial.color; renderer.material.color = Color.yellow; // notice how I use material and not sharedmaterial - this is to prevent affecting all clone instances - we just want to color this one, so we need to make this material unique. }
// Create tank instance and add it to the map GameObjectAnimator DropTankOnPosition(Vector2 mapPosition) { GameObject tankGO = Instantiate(Resources.Load <GameObject> ("Tank/CompleteTank")); GameObjectAnimator tank = tankGO.WMSK_MoveTo(mapPosition); tank.autoRotation = true; tank.attrib ["Color"] = tank.GetComponentInChildren <Renderer> ().sharedMaterial.color; return(tank); }