Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using TMPro;
- [RequireComponent (typeof(TextMeshPro))]
- public class Fukkntyper : MonoBehaviour {
- TextMeshPro _textmesh;
- string[] _textCharacter;
- public bool _isActive;
- public float _timeinsex;
- public float _TimeTillOn = 5f;
- public float _ShortyTime = 5f;
- private bool _timestop = false;
- public AudioSource Typesound;
- public AudioClip kboot;//if this is here, I didn't find a way to hook up a clicking sound to each letter popup
- float _timah;
- int _charKount;
- // Use this for initialization
- //Definition junk. Had to follow a guide on writing this. Tried doing it more blindly but ended up crashing unity. This is better though.
- void Start () { Typesound = GetComponent<AudioSource>();
- _textmesh = GetComponent<TextMeshPro> ();
- _textCharacter = new string[_textmesh.text.Length];
- for (int i = 0; i < _textmesh.text.Length; i++) {
- _textCharacter [i] = _textmesh.text.Substring (i, 1);
- }
- _textmesh.text = "";
- _charKount = 0;
- _timah = 0;
- }
- // Update is called once per frame
- // hung over while reading through this. increases time the script is active for each character
- void Update () {
- _TimeTillOn -= Time.deltaTime;
- _ShortyTime -= Time.deltaTime;
- if (_TimeTillOn <= 0)
- if (_isActive)
- {
- if (_charKount < _textCharacter.Length) {
- _timah += Time.deltaTime;
- if (_timah >= _timeinsex) {
- _textmesh.text += _textCharacter [_charKount];
- _charKount++;
- _timah = 0;
- Typesound.PlayOneShot (kboot);
- }
- }
- //Any child TextObjPros will respond after the first
- if (_charKount == _textCharacter.Length) {
- if (transform.childCount > 0) {
- if (_ShortyTime <= 0)
- transform.GetChild (0).GetComponent<Fukkntyper> ()._isActive = true;
- _charKount++;
- }
- }
- }
- }
- //Collision functions
- void OnTriggerEnter(Collider col)
- {
- if (col.GetComponent<Rigidbody> ()) {
- _isActive = true;
- }
- }
- }
- //
- The problem is that both the parents and children are connected to the same deltatime. As such, you need to do guesswork to syncronize activations. What I want to be able to do is have the children be connected to an independant timer that activates when the one text object is done printing.
- I've spent a few hours trying to find a way to do this. Fuck me. As is, the children activate when the parent is done printing AND the main timer hits zero. I want them on independant timers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement