Story box appears when called, disappears when clicked

This commit is contained in:
henriquenakashima 2020-09-27 22:04:05 -04:00
parent 8eecb71a38
commit 8119482922
4 changed files with 12 additions and 101 deletions

View file

@ -5,6 +5,7 @@ using UnityEngine;
public class Scene_Chapter1_Cave: StoryScene
{
public override IEnumerator Play(StoryDisplay storyDisplay) {
yield return new WaitForSeconds(1f);
yield return storyDisplay.DisplayText("OMG monsters!");
yield return new WaitForSeconds(1f);

View file

@ -11,11 +11,16 @@ public class StoryBox : MonoBehaviour {
private bool clicked;
void Awake() {
this.gameObject.SetActive(false);
}
void Start() {
this.button.onClick.AddListener(NotifyOnClick);
}
public IEnumerator Display(string message) {
this.gameObject.SetActive(true);
this.clicked = false;
this.text.text = message;
while (!this.clicked) {
@ -25,5 +30,6 @@ public class StoryBox : MonoBehaviour {
private void NotifyOnClick() {
this.clicked = true;
this.gameObject.SetActive(false);
}
}

View file

@ -7,18 +7,6 @@ public class StoryDisplay : MonoBehaviour
{
public StoryBox storyBox;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public IEnumerator DisplayText(string message) {
yield return this.storyBox.Display(message);
}

View file

@ -177,7 +177,7 @@ GameObject:
- component: {fileID: 787163456}
- component: {fileID: 787163455}
m_Layer: 5
m_Name: Text (TMP)
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -195,7 +195,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1465315969}
m_RootOrder: 3
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
@ -567,10 +567,9 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1748269587}
- {fileID: 2115462303}
- {fileID: 1220087265}
- {fileID: 787163454}
- {fileID: 1220087265}
m_Father: {fileID: 1957655126}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -591,91 +590,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0e8e862c9eaf8d44694147ff5e9873af, type: 3}
m_Name:
m_EditorClassIdentifier:
text: {fileID: 1748269588}
text: {fileID: 787163455}
button: {fileID: 1220087266}
--- !u!1 &1748269586
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1748269587}
- component: {fileID: 1748269589}
- component: {fileID: 1748269588}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &1748269587
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1748269586}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1465315969}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -40, y: -40}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1748269588
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1748269586}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 90f983b71ca63c34fb734819674536e0, type: 3}
m_FontSize: 30
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 0
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.
--- !u!222 &1748269589
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1748269586}
m_CullTransparentMesh: 0
--- !u!1 &1778892268
GameObject:
m_ObjectHideFlags: 0
@ -955,7 +871,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1465315969}
m_RootOrder: 1
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}