Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class DialogControl : MonoBehaviour
- {
- public float textXLeft = -235.0f;
- public float textXRight = 235.0f;
- public int state = 0;
- public Text dialogText;
- public GameObject[] dialogObjects;
- public void Next()
- {
- state++;
- switch (state)
- {
- case 1:
- MoveDialogObjects(textXRight);
- dialogText.text = "I know, right?!";
- break;
- case 2:
- MoveDialogObjects(textXLeft);
- dialogText.text = "Tottaly.";
- break;
- case 3:
- dialogText.text = "Hey did you hear about...";
- break;
- case 4:
- MoveDialogObjects(textXRight);
- dialogText.text = "wow!!";
- break;
- default:
- HideAllDialog();
- break;
- }
- }
- public void MoveDialogObjects(float newX)
- {
- foreach (GameObject dialogObject in dialogObjects)
- {
- // Moves dialogObject to newX and uses the existing Y
- RectTransform rectTransform = dialogObject.GetComponent<RectTransform>();
- if (rectTransform != null)
- {
- float y = rectTransform.localPosition.y;
- rectTransform.localPosition = new Vector3(newX, y);
- }
- }
- }
- public void HideAllDialog()
- {
- foreach (GameObject dialogObject in dialogObjects)
- {
- dialogObject.SetActive(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement