衝突した位置情報を取得して、その位置にエフェクトを発生させる方法
![35d07b8a a12e 4c2c 8627 a4ab79061157](https://codegenius.org/uploads/slide/image/2328/35d07b8a-a12e-4c2c-8627-a4ab79061157.jpeg)
衝突位置にエフェクトを発生させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject_B : MonoBehaviour {
public GameObject effectPrefab;
void OnCollisionEnter(Collision other){
if (other.gameObject.tag == "Shell") {
Destroy (other.gameObject);
foreach (ContactPoint contactPoint in other.contacts) {
GameObject effect = (GameObject)Instantiate (effectPrefab, (Vector3)contactPoint.point, Quaternion.identity);
// 衝突位置を確認してみる。
print ((Vector3)contactPoint.point);
Destroy (effect, 1.5f);
}
}
}
}
![7992f842 1247 4dd7 87a4 7f2087638da8](https://codegenius.org/uploads/slide/image/2329/7992f842-1247-4dd7-87a4-7f2087638da8.jpeg)
Unity Code Memo
他のコースを見る![35d07b8a a12e 4c2c 8627 a4ab79061157](https://codegenius.org/uploads/slide/image/2328/35d07b8a-a12e-4c2c-8627-a4ab79061157.jpeg)
衝突位置にエフェクトを発生させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject_B : MonoBehaviour {
public GameObject effectPrefab;
void OnCollisionEnter(Collision other){
if (other.gameObject.tag == "Shell") {
Destroy (other.gameObject);
foreach (ContactPoint contactPoint in other.contacts) {
GameObject effect = (GameObject)Instantiate (effectPrefab, (Vector3)contactPoint.point, Quaternion.identity);
// 衝突位置を確認してみる。
print ((Vector3)contactPoint.point);
Destroy (effect, 1.5f);
}
}
}
}
![7992f842 1247 4dd7 87a4 7f2087638da8](https://codegenius.org/uploads/slide/image/2329/7992f842-1247-4dd7-87a4-7f2087638da8.jpeg)
衝突した位置情報を取得して、その位置にエフェクトを発生させる方法