FireBallの作成









FireBallに当たるとダメージを受ける
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerHP : MonoBehaviour
{
private Animator animator;
public AudioClip sound;
void Start()
{
animator = GetComponent<Animator>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
// ★改良(FireBall)
if(collision.gameObject.CompareTag("Enemy"))
{
Damage();
}
// ★追加(FireBall)
else if (collision.gameObject.CompareTag("FireBall"))
{
Destroy(collision.gameObject);
Damage();
}
}
// ★追加(FireBall)
void Damage()
{
animator.SetTrigger("Damage");
AudioSource.PlayClipAtPoint(sound, transform.position);
Invoke("Restart", 0.5f);
}
void Restart()
{
SceneManager.LoadScene("Main");
}
}


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








FireBallに当たるとダメージを受ける
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerHP : MonoBehaviour
{
private Animator animator;
public AudioClip sound;
void Start()
{
animator = GetComponent<Animator>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
// ★改良(FireBall)
if(collision.gameObject.CompareTag("Enemy"))
{
Damage();
}
// ★追加(FireBall)
else if (collision.gameObject.CompareTag("FireBall"))
{
Destroy(collision.gameObject);
Damage();
}
}
// ★追加(FireBall)
void Damage()
{
animator.SetTrigger("Damage");
AudioSource.PlayClipAtPoint(sound, transform.position);
Invoke("Restart", 0.5f);
}
void Restart()
{
SceneManager.LoadScene("Main");
}
}


FireBallの作成