Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- namespace AC
- {
- public class SnoopScript : MonoBehaviour
- {
- public Image snoopSprite;
- public Image portalSprite;
- public Canvas snoopCanvas;
- public float fadespeed = 2f;
- private Dictionary<Image, Hotspot> hotspotsDict = new Dictionary<Image, Hotspot>();
- void Update ()
- {
- if( snoopCanvas.transform.childCount > 0 )
- {
- foreach( Image sprite in hotspotsDict.Keys )
- {
- sprite.rectTransform.position = hotspotsDict[sprite].GetIconScreenPosition();
- }
- }
- if (Input.GetAxis ("FlashHotspots") == 1)
- {
- FlashHotspots();
- }
- }
- private void FlashHotspots ()
- {
- Hotspot[] hotspots = FindObjectsOfType (typeof (Hotspot)) as Hotspot[];
- foreach (Hotspot hotspot in hotspots)
- {
- if (hotspot.IsOn () && hotspot != KickStarter.playerInteraction.GetActiveHotspot ())
- {
- Image hotspotSnoop;
- if( hotspot.IsSingleInteraction() )
- {
- hotspotSnoop = Instantiate( portalSprite ) as Image;
- }
- else
- {
- hotspotSnoop = Instantiate( snoopSprite ) as Image;
- }
- hotspotSnoop.transform.SetParent(snoopCanvas.transform);
- hotspotSnoop.rectTransform.position = hotspot.GetIconScreenPosition();
- hotspotsDict.Add( hotspotSnoop, hotspot );
- StartCoroutine(FadeOut( hotspotSnoop ));
- }
- }
- }
- IEnumerator FadeOut(Image obj)
- {
- yield return new WaitForSeconds(1.0f);
- obj.CrossFadeAlpha (0.0f, fadespeed, false);
- while( obj.canvasRenderer.GetAlpha() > 0.0f )
- {
- yield return null;
- }
- Destroy (obj.gameObject);
- hotspotsDict.Remove (obj);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement