Created
October 25, 2014 06:22
-
-
Save hendrik-weiler/0d5a1b6b5460fe3c69cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
public class Bubble : MonoBehaviour { | |
protected GameObject bubble; | |
protected Text text; | |
private GameObject ui; | |
public bool createdBubble = false; | |
protected GameObject chara; | |
protected GameObject npc; | |
protected RectTransform trans; | |
protected MessageContainer container; | |
protected float CharByCharSteps = 300; | |
protected float CharByCharCounter = 0; | |
protected string message; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
if(ui == null) { | |
ui = Camera.main.GetComponent<GameManager>().GetUI(); | |
} | |
if(createdBubble) { | |
Vector2 pos = Camera.main.WorldToViewportPoint(chara.transform.position); | |
trans.position = new Vector2(pos.x, pos.y); | |
if(CharByCharCounter < this.message.Length) { | |
charByChar(CharByCharCounter+=1); | |
} | |
} | |
} | |
protected void charByChar(float show) { | |
string messageResult = ""; | |
for(int i = 0; i < show; ++i) { | |
messageResult+= this.message[i]; | |
} | |
text.text = messageResult; | |
} | |
// unused | |
protected IEnumerator AnimateCharacter(GameObject character) { | |
iTween.ScaleAdd(character, new Vector3(0f,0.2f,0),0.2f); | |
yield return new WaitForSeconds(0.1f); | |
iTween.ScaleAdd(character, new Vector3(0.15f,0f,0),0.2f); | |
yield return new WaitForSeconds(0.1f); | |
iTween.ScaleAdd(character, new Vector3(0f,-0.2f,0),0.2f); | |
yield return new WaitForSeconds(0.1f); | |
iTween.ScaleAdd(character, new Vector3(-0.15f,0f,0),0.2f); | |
yield return new WaitForSeconds(0.1f); | |
} | |
public void HideBubble() { | |
createdBubble = false; | |
Destroy(bubble); | |
} | |
public void ShowBubble(MessageContainer container, GameObject character, string message) { | |
this.CharByCharCounter = 0; | |
this.container = container; | |
this.chara = character; | |
bubble = Instantiate(Resources.Load("Prefabs/Speachbubble"),character.transform.position,Quaternion.identity) as GameObject; | |
bubble.transform.parent = ui.transform; | |
trans = bubble.GetComponent<RectTransform>(); | |
trans.position = new Vector3(trans.position.x,trans.position.y+0.5f,trans.position.z); | |
trans.localScale = new Vector3(1f,1f,1f); | |
text = bubble.transform.Find("Text").gameObject.GetComponent<Text>(); | |
this.message = message; | |
this.CharByCharSteps = message.Length; | |
//StartCoroutine(this.AnimateCharacter(character)); | |
createdBubble = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment