intro + texte avec image reutilisable

This commit is contained in:
esteb 2023-01-20 00:11:38 +01:00
parent d4996868f3
commit 610a7c1618
4 changed files with 884 additions and 2541 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueScript : MonoBehaviour
{
public Text textComponent;
public string[] lines;
public float textSpeed;
private int index;
public List<int> images;
private GameObject image;
private GameObject textImage;
public List<GameObject> imageAndTexts;
private int indexList = 0;
private void OnEnable()
{
textComponent.text = string.Empty;
StartDialogue();
}
// Update is called once per frame
void Update()
{
if(images.Contains(index))
{
SetImageStep();
}
if (Input.GetMouseButtonDown(0))
{
if(images.Contains(index - 1)){
DisableImageStep();
}
if (textComponent.text == lines[index])
{
NextLine();
}
else
{
StopAllCoroutines();
textComponent.text = lines[index];
}
}
}
public void StartDialogue()
{
index = 0;
StartCoroutine(TypeLine());
}
IEnumerator TypeLine()
{
foreach (char c in lines[index].ToCharArray())
{
textComponent.text += c;
yield return new WaitForSeconds(textSpeed);
}
}
public void NextLine()
{
if (index < lines.Length - 1)
{
index++;
textComponent.text = string.Empty;
StartCoroutine(TypeLine());
}
else
{
gameObject.SetActive(false);
}
}
private void SetImageStep(){
textImage = imageAndTexts[indexList];
indexList ++;
image = imageAndTexts[indexList];
indexList ++;
image.SetActive(true);
textImage.SetActive(true);
index ++;
}
private void DisableImageStep(){
image.SetActive(false);
textImage.SetActive(false);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 883d6d7c4a541f749909e8bca50cf339
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long