// Update is called once per frame void Update() { RaycastHit hitInfo; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo) && hitInfo.collider.gameObject.CompareTag("Gazable")) { Debug.Log(hitInfo.collider.name); //canRotate = true; Debug.Log("On Gazable"); cachedObj = hitInfo.collider.gameObject; Gazable gazableScript = cachedObj.GetComponent <Gazable> (); if (!gazableScript.fairyLights.isPlaying) { gazableScript.fairyLights.Play(); } gazableScript.gazedCount += Time.deltaTime * 50; Debug.Log("gazedCount: " + gazableScript.gazedCount); if (gazableScript.gazedCount > 60) { gazableScript.Explode(); gazableScript.fairyLights.Stop(); } if (gazableScript.gazedCount > 110) { Destroy(cachedObj); cachedObj = null; } } else if (cachedObj != null) { Gazable gazableScript = cachedObj.GetComponent <Gazable> (); gazableScript.fairyLights.Stop(); cachedObj = null; } }
// Use this for initialization void Start() { cam = Camera.main; gazable = GetComponent <Gazable>(); PlayingPlayer = FindObjectOfType <MediaPlayer>(); }