// Use this for initialization void Start() { ImageTarget = GameObject.FindGameObjectWithTag("ImageTarget"); theCamera = GameObject.FindGameObjectWithTag("MainCamera"); f_CurrentZoomPercent = -1; theState = ZOOM_STATE.NORMAL; ZoomOutSprite = GetComponent <Image>().sprite; }
void ZoomIn() { GetComponent <Image>().sprite = ZoomOutSprite; SpriteState newState = new SpriteState(); newState.highlightedSprite = ZoomOutHighlightedSprite; GetComponent <Button>().spriteState = newState; GetComponentInParent <UISwitchOff>().SwitchOn(); b_ZoomIn = true; b_ZoomOut = false; theState = ZOOM_STATE.IN_PROGRESS; }
// Update is called once per frame void Update() { if (PersistentData.m_Instance.TutorialOver) { GetComponent <Image>().enabled = true; } else { GetComponent <Image>().enabled = false; } if (ImageTarget.GetComponentInChildren <Renderer>().enabled&& f_CurrentZoomPercent == -1) { f_CurrentZoomPercent = (theCamera.transform.position - ImageTarget.transform.position).magnitude; f_OrignalZoomPercent = f_CurrentZoomPercent; } if (b_ZoomIn) { GameObject.FindGameObjectWithTag("MainCamera").transform.Translate(0, 0, Time.deltaTime); f_CurrentZoomPercent = ((theCamera.transform.position - ImageTarget.transform.position).magnitude / f_OrignalZoomPercent) * 100; if (f_CurrentZoomPercent < ZoomedInPercent) { b_ZoomIn = false; theState = ZOOM_STATE.NORMAL; } } if (b_ZoomOut) { GameObject.FindGameObjectWithTag("MainCamera").transform.Translate(0, 0, -Time.deltaTime); f_CurrentZoomPercent = ((theCamera.transform.position - ImageTarget.transform.position).magnitude / f_OrignalZoomPercent) * 100; if (f_CurrentZoomPercent > ZoomedOutPercent) { b_ZoomOut = false; theState = ZOOM_STATE.ZOOMED_OUT; } } }