ボス・ステージの作成3(ボスタイトルの表示)




BossTitle
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加(BossTitle)
using UnityEngine.UI;
public class BossTrap : MonoBehaviour
{
public AudioClip closeSound;
public GameObject door_1;
public GameObject boss;
public AudioClip bossSound;
public AudioSource bgm;
// ★追加(BossTitle)
public GameObject bossTitle;
public string titleName;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Player"))
{
StartCoroutine(Trap());
}
}
private IEnumerator Trap()
{
AudioSource.PlayClipAtPoint(closeSound, Camera.main.transform.position);
door_1.SetActive(true);
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
yield return new WaitForSeconds(1f);
// ★追加(BossTitle)
// ボスタイトルの表示
bossTitle.SetActive(true);
// タイトル文のセット
bossTitle.GetComponent<Text>().text = titleName;
bgm.clip = bossSound;
bgm.Play();
boss.SetActive(true);
// ★追加(BossTitle)
yield return new WaitForSeconds(3f);
// ボスタイトルを非表示に戻す
bossTitle.SetActive(false);
}
}


【2022版】DarkCastle(全39回)
他のコースを見る



BossTitle
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加(BossTitle)
using UnityEngine.UI;
public class BossTrap : MonoBehaviour
{
public AudioClip closeSound;
public GameObject door_1;
public GameObject boss;
public AudioClip bossSound;
public AudioSource bgm;
// ★追加(BossTitle)
public GameObject bossTitle;
public string titleName;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Player"))
{
StartCoroutine(Trap());
}
}
private IEnumerator Trap()
{
AudioSource.PlayClipAtPoint(closeSound, Camera.main.transform.position);
door_1.SetActive(true);
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
yield return new WaitForSeconds(1f);
// ★追加(BossTitle)
// ボスタイトルの表示
bossTitle.SetActive(true);
// タイトル文のセット
bossTitle.GetComponent<Text>().text = titleName;
bgm.clip = bossSound;
bgm.Play();
boss.SetActive(true);
// ★追加(BossTitle)
yield return new WaitForSeconds(3f);
// ボスタイトルを非表示に戻す
bossTitle.SetActive(false);
}
}


ボス・ステージの作成3(ボスタイトルの表示)