手榴弾の爆風(エフェクト)でダメージを与える



爆風でダメージを与える
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrenadeDamage : MonoBehaviour
{
void OnParticleCollision(GameObject other)
{
if (other.gameObject.tag == "Enemy")
{
Destroy(other.gameObject);
}
}
}





爆風で吹き飛ばす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrenadeDamage : MonoBehaviour {
// ★修正
private float radius = 20.0f;
private float power = 100.0f;
// ★修正
void OnParticleCollision(GameObject other)
{
Vector3 explosionPos = transform.position;
Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
foreach (Collider hit in colliders)
{
Rigidbody rb = hit.GetComponent<Rigidbody>();
if (rb != null)
{
rb.AddExplosionForce(power, explosionPos, 15.0f);
}
if (hit.gameObject.tag == "Enemy")
{
Destroy(hit.gameObject, 1.5f);
}
}
}
}


EscapeCombat
他のコースを見る


爆風でダメージを与える
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrenadeDamage : MonoBehaviour
{
void OnParticleCollision(GameObject other)
{
if (other.gameObject.tag == "Enemy")
{
Destroy(other.gameObject);
}
}
}





爆風で吹き飛ばす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrenadeDamage : MonoBehaviour {
// ★修正
private float radius = 20.0f;
private float power = 100.0f;
// ★修正
void OnParticleCollision(GameObject other)
{
Vector3 explosionPos = transform.position;
Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
foreach (Collider hit in colliders)
{
Rigidbody rb = hit.GetComponent<Rigidbody>();
if (rb != null)
{
rb.AddExplosionForce(power, explosionPos, 15.0f);
}
if (hit.gameObject.tag == "Enemy")
{
Destroy(hit.gameObject, 1.5f);
}
}
}
}


手榴弾の爆風(エフェクト)でダメージを与える