敵を踏みつけて倒せるようにする


敵を踏みつけて倒す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FootAttack : MonoBehaviour
{
public AudioClip sound;
private void Update()
{
RaycastHit2D hit2d = Physics2D.Raycast(transform.position, Vector2.down, 0.6f);
if(hit2d.collider != null) // この条件は重要
{
if(hit2d.collider.CompareTag("Enemy"))
{
Destroy(hit2d.collider.gameObject);
AudioSource.PlayClipAtPoint(sound, transform.position);
}
}
// 可視化
Debug.DrawRay(transform.position, Vector3.down, Color.yellow, 0.6f);
}
}



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

敵を踏みつけて倒す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FootAttack : MonoBehaviour
{
public AudioClip sound;
private void Update()
{
RaycastHit2D hit2d = Physics2D.Raycast(transform.position, Vector2.down, 0.6f);
if(hit2d.collider != null) // この条件は重要
{
if(hit2d.collider.CompareTag("Enemy"))
{
Destroy(hit2d.collider.gameObject);
AudioSource.PlayClipAtPoint(sound, transform.position);
}
}
// 可視化
Debug.DrawRay(transform.position, Vector3.down, Color.yellow, 0.6f);
}
}



敵を踏みつけて倒せるようにする