public void OnInstalledObjectPlaced(InstalledObject placedObject) { // Create the visual representation (GameObject) of the InstalledObject. // TODO: Does not work with objects larger than 1 tile right now or rotated objects! GameObject installedObjectGameObject = new GameObject(); installedObjectGameObject.name = placedObject.installedObjectType + "_" + placedObject.tile.x + "," + placedObject.tile.y; installedObjectGameObject.transform.position = new Vector3(placedObject.tile.x, placedObject.tile.y); installedObjectGameObject.transform.SetParent(transform, true); // Add the InstalledObject data and GameObject to the map. installedObjectGameObjectMap.Add(placedObject, installedObjectGameObject); // Add a SpriteRenderer to the InstalledObject. SpriteRenderer spriteRenderer = installedObjectGameObject.AddComponent <SpriteRenderer>(); if (!placedObject.installed) { spriteRenderer.color = new Color(1f, 1f, 1f, 0.3f); } else { spriteRenderer.color = new Color(1f, 1f, 1f, 1f); } switch (placedObject.installedObjectType) { case InstalledObjectType.Wall: spriteRenderer.sprite = GetSpriteForInstalledObject(placedObject); spriteRenderer.sortingLayerName = "InstalledObject"; break; default: Debug.LogError("OnInstalledObjectPlaced - Invalid InstalledObject type."); break; } // Register the InstalledObject changed callback. placedObject.RegisterChanged(OnInstalledObjectChanged); }