敵を踏みつけた時、少しホップさせる
敵を踏みつけた時、ホップする
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FootAttack : MonoBehaviour
{
public AudioClip sound;
// ★追加(ホップ)
private Rigidbody2D rb2d;
// ★追加(ホップ)
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;
}
}
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;
// ★追加(ホップ)
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;
}
}
Debug.DrawRay(transform.position, Vector3.down, Color.yellow, 0.6f);
}
}
敵を踏みつけた時、少しホップさせる