// show a preview of the new item private void RefreshStoreItem() { if (storeItemPreview != null) { Destroy(storeItemPreview); } Transform activePreviewTransform = null; if (storeSelectingPowerUp) { storeItemPreview = GameObject.Instantiate(dataManager.GetPowerUpPrefab((PowerUpTypes)storeItemIndex)) as GameObject; #if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5) if (useuGUI) { storeItemPreview.transform.parent = storePowerUpPreviewTransform.parent; } #endif storeItemPreview.transform.localScale = storePowerUpPreviewTransform.localScale; activePreviewTransform = storePowerUpPreviewTransform; } else { // don't want to override PlayerController.instance when the new player controller gets instantiated PlayerController playerController = PlayerController.instance; storeItemPreview = GameObject.Instantiate(dataManager.GetCharacterPrefab(storeItemIndex)) as GameObject; storeItemPreview.GetComponent <PlayerController>().ActivatePowerUp(PowerUpTypes.CoinMagnet, false); PlayerController.instance = playerController; #if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5) if (useuGUI) { storeItemPreview.transform.parent = storeCharacterPreviewTransform.parent; } #endif storeItemPreview.transform.localScale = storeCharacterPreviewTransform.localScale; // set the character to be the same scale as the preview transform activePreviewTransform = storeCharacterPreviewTransform; } storeItemPreview.transform.position = activePreviewTransform.position; storeItemPreview.transform.rotation = activePreviewTransform.rotation; // disable all of the componenets to prevent any scripts from running. Also set the layer so only the GUI camera can see it int layer = 0; #if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5) if (useuGUI) { layer = LayerMask.NameToLayer("UI"); storeItemPreview.AddComponent <CanvasRenderer>(); } else { #endif #if COMPILE_NGUI layer = LayerMask.NameToLayer("GUI"); #endif #if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5) } #endif storeItemPreview.gameObject.layer = layer; ChangeLayers(storeItemPreview.transform, layer); foreach (Behaviour childCompnent in storeItemPreview.GetComponentsInChildren <Behaviour>()) { childCompnent.enabled = false; } if (storeItemPreview.GetComponent <Rigidbody>()) { storeItemPreview.GetComponent <Rigidbody>().isKinematic = true; } PlayerAnimation playerAnimation = null; if ((playerAnimation = storeItemPreview.GetComponent <PlayerAnimation>()) != null) { if (playerAnimation.useMecanim) { storeItemPreview.GetComponent <Animator>().enabled = true; storeItemPreview.GetComponent <Animator>().SetFloat("Speed", 0); } else { storeItemPreview.GetComponent <Animation>().enabled = true; playerAnimation.Idle(); } } }