敵を踏みつけた時、専用のエフェクトを出す







踏みつけて、エフェクト発生
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FootAttack : MonoBehaviour
{
public AudioClip sound;
private Rigidbody2D rb2d;
// ★追加(エフェクト発生)
public GameObject effectPrefab;
private void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
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);
rb2d.velocity = Vector2.up * 3.5f;
// ★追加(エフェクト発生)
Instantiate(effectPrefab, hit2d.collider.transform.position, Quaternion.identity);
}
}
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 Rigidbody2D rb2d;
// ★追加(エフェクト発生)
public GameObject effectPrefab;
private void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
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);
rb2d.velocity = Vector2.up * 3.5f;
// ★追加(エフェクト発生)
Instantiate(effectPrefab, hit2d.collider.transform.position, Quaternion.identity);
}
}
Debug.DrawRay(transform.position, Vector3.down, Color.yellow, 0.6f);
}
}


敵を踏みつけた時、専用のエフェクトを出す