public void SpawnVersion(RepairState newState) { currentState = newState; if (spawnedVersion != null) { HilightMaterialSwitcher hmatSwitcher = spawnedVersion.GetComponentInChildren <HilightMaterialSwitcher>(); HilightAllMaterialsSwitcher hmatAllSwitcher = spawnedVersion.GetComponentInChildren <HilightAllMaterialsSwitcher>(); if (hmatSwitcher != null) { GetComponent <Interactable>().hilightChangedDelegate -= hmatSwitcher.OnHilightChanged; } if (hmatAllSwitcher != null) { GetComponent <Interactable>().hilightChangedDelegate -= hmatAllSwitcher.OnHilightChanged; } Destroy(spawnedVersion.gameObject); } switch (newState) { case RepairState.Repaired: spawnedVersion = Instantiate(repairedPrefab, transform); break; case RepairState.Twisted: spawnedVersion = Instantiate(twistedPrefab, transform); break; case RepairState.Unpainted: spawnedVersion = Instantiate(unpaintedPrefab, transform); break; case RepairState.Damaged: spawnedVersion = Instantiate(damagedPrefab, transform); break; } { HilightMaterialSwitcher hmatSwitcher = spawnedVersion.GetComponentInChildren <HilightMaterialSwitcher>(); HilightAllMaterialsSwitcher hmatAllSwitcher = spawnedVersion.GetComponentInChildren <HilightAllMaterialsSwitcher>(); if (hmatSwitcher != null) { GetComponent <Interactable>().hilightChangedDelegate += hmatSwitcher.OnHilightChanged; } if (hmatAllSwitcher != null) { GetComponent <Interactable>().hilightChangedDelegate += hmatAllSwitcher.OnHilightChanged; } } }
public void OnDestroy() { if (spawnedVersion != null) { HilightMaterialSwitcher hmatSwitcher = spawnedVersion.GetComponentInChildren <HilightMaterialSwitcher>(); HilightAllMaterialsSwitcher hmatAllSwitcher = spawnedVersion.GetComponentInChildren <HilightAllMaterialsSwitcher>(); if (hmatSwitcher != null) { GetComponent <Interactable>().hilightChangedDelegate += hmatSwitcher.OnHilightChanged; } if (hmatAllSwitcher != null) { GetComponent <Interactable>().hilightChangedDelegate += hmatAllSwitcher.OnHilightChanged; } } }