Advertisement
Guest User

ssss

a guest
Dec 11th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using TMPro;
  4.  
  5. [RequireComponent (typeof(TextMeshPro))]
  6. public class Fukkntyper : MonoBehaviour {
  7. TextMeshPro _textmesh;
  8. string[] _textCharacter;
  9. public bool _isActive;
  10. public float _timeinsex;
  11. public float _TimeTillOn = 5f;
  12. public float _ShortyTime = 5f;
  13. private bool _timestop = false;
  14. public AudioSource Typesound;
  15. public AudioClip kboot;//if this is here, I didn't find a way to hook up a clicking sound to each letter popup
  16. float _timah;
  17. int _charKount;
  18. // Use this for initialization
  19. //Definition junk. Had to follow a guide on writing this. Tried doing it more blindly but ended up crashing unity. This is better though.
  20. void Start () { Typesound = GetComponent<AudioSource>();
  21.  
  22.  
  23.  
  24. _textmesh = GetComponent<TextMeshPro> ();
  25. _textCharacter = new string[_textmesh.text.Length];
  26. for (int i = 0; i < _textmesh.text.Length; i++) {
  27. _textCharacter [i] = _textmesh.text.Substring (i, 1);
  28. }
  29. _textmesh.text = "";
  30. _charKount = 0;
  31. _timah = 0;
  32. }
  33. // Update is called once per frame
  34. // hung over while reading through this. increases time the script is active for each character
  35. void Update () {
  36. _TimeTillOn -= Time.deltaTime;
  37. _ShortyTime -= Time.deltaTime;
  38. if (_TimeTillOn <= 0)
  39. if (_isActive)
  40. {
  41. if (_charKount < _textCharacter.Length) {
  42. _timah += Time.deltaTime;
  43. if (_timah >= _timeinsex) {
  44. _textmesh.text += _textCharacter [_charKount];
  45. _charKount++;
  46. _timah = 0;
  47. Typesound.PlayOneShot (kboot);
  48.  
  49. }
  50. }
  51. //Any child TextObjPros will respond after the first
  52. if (_charKount == _textCharacter.Length) {
  53. if (transform.childCount > 0) {
  54.  
  55. if (_ShortyTime <= 0)
  56.  
  57. transform.GetChild (0).GetComponent<Fukkntyper> ()._isActive = true;
  58. _charKount++;
  59.  
  60. }
  61. }
  62. }
  63. }
  64. //Collision functions
  65. void OnTriggerEnter(Collider col)
  66. {
  67. if (col.GetComponent<Rigidbody> ()) {
  68. _isActive = true;
  69. }
  70. }
  71. }
  72. //
  73. 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.
  74.  
  75. 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