//When a letter is dropped over a drop area this is function is called //to set the parent to the drop area and the position to the mouse position public void OnDrop(PointerEventData eventData) { LetterScript ls = eventData.pointerDrag.GetComponent <LetterScript> (); if (ls != null) { ls.SetPosition(eventData.position, this.gameObject); } }
private void Commands(LetterScript letter) { if (!_rainbow) { if (_secondaryCol) { letter.InitEffects(_currEffect, _secColor); } else { letter.InitEffects(_currEffect, _defColor); } } else { letter.InitEffects(_currEffect, true); } //sound //if (Time.frameCount % 3 == 0) // _snd.Play("Blip", false, 0); switch (letter.Letter) { case '#': Destroy(letter.transform.parent.gameObject); break; case '£': Destroy(letter.transform.parent.gameObject); if (_currEffect == LetterScript.TextEffect.Wavy) { _currEffect = LetterScript.TextEffect.Normal; } else { _currEffect = LetterScript.TextEffect.Wavy; } break; case '%': Destroy(letter.transform.parent.gameObject); if (_currEffect == LetterScript.TextEffect.Shaky) { _currEffect = LetterScript.TextEffect.Normal; } else { _currEffect = LetterScript.TextEffect.Shaky; } break; case '*': Destroy(letter.transform.parent.gameObject); _secondaryCol = !_secondaryCol; break; case '$': Destroy(letter.transform.parent.gameObject); _rainbow = !_rainbow; break; case '°': Destroy(letter.transform.parent.gameObject); break; default: break; } }
// Update is called once per frame void Update() { //do text if (_line1 != null) { if (Time.frameCount % _textDelay == 0) { if (_line1Index < _line1.Length) { LetterScript letter = Instantiate(_letterPrefab, _line1Object.transform).transform.GetChild(0).GetComponent <LetterScript>(); letter.Letter = _line1.ToCharArray()[_line1Index]; letter.Index = _line1Index; Commands(letter); _line1Index++; if (letter.gameObject) { _letterDump.Add(letter); } } else if (_line2 != null) { if (_line2Index < _line2.Length) { LetterScript letter = Instantiate(_letterPrefab, _line2Object.transform).transform.GetChild(0).GetComponent <LetterScript>(); letter.Letter = _line2.ToCharArray()[_line2Index]; letter.Index = _line2Index; Commands(letter); _line2Index++; if (letter.gameObject) { _letterDump.Add(letter); } } else if (_line3 != null) { if (_line3Index < _line3.Length) { LetterScript letter = Instantiate(_letterPrefab, _line3Object.transform).transform.GetChild(0).GetComponent <LetterScript>(); letter.Letter = _line3.ToCharArray()[_line3Index]; letter.Index = _line3Index; Commands(letter); _line3Index++; if (letter.gameObject) { _letterDump.Add(letter); } } else { _doTimer = true; } } else { _doTimer = true; } } else { _doTimer = true; } if (_doTimer) { //count down timer if not wait for input if (!_waitForInput) { _waitTimer -= Time.deltaTime; } //press to continue if (Input.GetButtonDown("Fire2")) { _waitTimer = 0; } //stop or go to next text if (_waitTimer <= 0) { _doTimer = false; if (_index < _text.Length - 1) { PrintLine(); } else { //close animation _mask.transform.localScale = Vector2.Lerp(_mask.transform.localScale, new Vector2(0, 1), 0.4f); _isClosing = true; if (Vector2.Distance(_mask.transform.localScale, new Vector2(0, 1)) < 0.1f) { _isClosing = false; ResetLetters(); _mask.gameObject.SetActive(false); _mask.transform.localScale = new Vector2(0, 1); } } } } } } //appear animation if (_mask.gameObject.activeSelf && !_isClosing) { _mask.transform.localScale = Vector2.Lerp(_mask.transform.localScale, Vector2.one, 0.1f); } }