トラップの作成2(Playerがダメージを受ける)
ダメージを受ける
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHP : MonoBehaviour
{
public AudioClip damageSound;
private Animator animator;
private void Start()
{
animator = GetComponent<Animator>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.CompareTag("Trap"))
{
animator.SetTrigger("Damage");
AudioSource.PlayClipAtPoint(damageSound, transform.position);
}
}
}
【2022版】ActionGame2D(全33回)
他のコースを見るダメージを受ける
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHP : MonoBehaviour
{
public AudioClip damageSound;
private Animator animator;
private void Start()
{
animator = GetComponent<Animator>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.CompareTag("Trap"))
{
animator.SetTrigger("Damage");
AudioSource.PlayClipAtPoint(damageSound, transform.position);
}
}
}
トラップの作成2(Playerがダメージを受ける)