Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- using FMODUnity;
- public class SecretMessage : MonoBehaviour
- {
- public enum SpecificMode { Secret, Devmode};
- public SpecificMode mode;
- [SerializeField] private string message;
- [SerializeField] private BoxCollider2D collider;
- private GameObject player;
- [SerializeField] private TextMeshPro displayText;
- [SerializeField] private GameObject displayBackground;
- private bool hasStarted;
- [Tooltip("Hexadecimal color code after $")]
- [SerializeField] private string default_color_hex;
- [Tooltip("Hexadecimal color code after @")]
- [SerializeField] private string highlight_color_hex;
- [Tooltip("Hexadecimal color code after %")]
- [SerializeField] private string secondary_highlight_color_hex;
- [Tooltip("pause time when using *")]
- [SerializeField] private float extra_delay_seconds;
- [Header("Audio Refs")]
- [SerializeField] private EventReference _generatingTextAudio;
- [Header("devmode icon")]
- [SerializeField] private Sprite devIcon;
- [SerializeField] private SpriteRenderer devIconRenderer;
- // Update is called once per frame
- void Start()
- {
- player = GameObject.Find("Protagonist");
- //determines which mode is active.
- if(mode == SpecificMode.Secret)
- {
- if(PlayerPrefs.GetInt("secret") == 0)
- {
- this.gameObject.SetActive(false);
- }
- }
- else if(mode == SpecificMode.Devmode)
- {
- if(devIconRenderer != null && devIcon != null)
- {
- devIconRenderer.sprite = devIcon;
- }
- if(PlayerPrefs.GetInt("devmode") == 0)
- {
- this.gameObject.SetActive(false);
- }
- }
- }
- void Update()
- {
- Rect rect = new Rect(this.transform.position.x + collider.offset.x - (collider.size.x / 2), this.transform.position.y + collider.offset.y - (collider.size.y / 2), collider.size.x, collider.size.y);
- if (rect.Contains(player.transform.position) && !hasStarted)
- {
- displayText.text = "";
- displayText.text += "<color=" + default_color_hex + ">";
- StartCoroutine(PlayText(message));
- }
- }
- private void OnDrawGizmos()
- {
- DrawRect(new Rect(this.transform.position.x + collider.offset.x - (collider.size.x / 2), this.transform.position.y + collider.offset.y - (collider.size.y / 2), collider.size.x, collider.size.y));
- }
- void DrawRect(Rect rect)
- {
- Gizmos.DrawWireCube(new Vector3(rect.center.x, rect.center.y, 0.01f), new Vector3(rect.size.x, rect.size.y, 0.01f));
- }
- IEnumerator PlayText(string text)
- {
- hasStarted = true;
- displayBackground.SetActive(true);
- foreach (char c in text)
- {
- if(c == 43)
- {
- //+
- displayText.text += "<br>";
- }
- else if(c == 64)
- {
- //@
- displayText.text += "<color=" + highlight_color_hex + ">";
- }
- else if(c == 37)
- {
- //%
- displayText.text += "<color=" + secondary_highlight_color_hex + ">";
- }
- else if(c == 36)
- {
- //$
- displayText.text += "<color=" + default_color_hex + ">";
- }
- else if(c == 42)
- {
- //*
- yield return new WaitForSeconds (extra_delay_seconds);
- }
- else
- {
- if(devIconRenderer != null && devIcon != null)
- {
- devIconRenderer.gameObject.GetComponent<Animation>().Play();
- }
- RuntimeManager.PlayOneShot(_generatingTextAudio);
- displayText.text += c;
- yield return new WaitForSeconds (0.06f);
- }
- }
- if(mode == SpecificMode.Devmode)
- {
- yield return new WaitForSeconds (8f);
- displayBackground.SetActive(false);
- this.gameObject.SetActive(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement