着弾点でエフェクト発生


DestroyObjectの改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour {
public GameObject effectPrefab;
public AudioClip effectSound;
void OnCollisionEnter(Collision other){
if (other.gameObject.tag == "Bullet" || other.gameObject.tag == "Rocket") {
Destroy (other.gameObject);
Destroy (gameObject);
AudioSource.PlayClipAtPoint (effectSound, Camera.main.transform.position);
// ★追加
// (ポイント)「foreach」の意味と使い方を調べましょう!
foreach(ContactPoint contactPoint in other.contacts){
// ★修正
// 着弾点をエフェクトの発生位置に指定する。
GameObject effect = (GameObject)Instantiate (effectPrefab, contactPoint.point, Quaternion.identity);
Destroy (effect, 1.0f);
}
}
}
}

DestroyObject2の改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject2 : MonoBehaviour {
public GameObject effectPrefab;
public AudioClip effectSound;
public AudioClip noDamageSound;
void OnCollisionEnter(Collision other){
if (other.gameObject.tag == "Rocket") {
Destroy (other.gameObject);
Destroy (gameObject);
AudioSource.PlayClipAtPoint (effectSound, Camera.main.transform.position);
// ★追加
// (ポイント)「foreach」の意味と使い方を調べましょう!
foreach(ContactPoint contactPoint in other.contacts){
// ★修正
// 着弾点をエフェクトの発生位置に指定する。
GameObject effect = (GameObject)Instantiate (effectPrefab, contactPoint.point, Quaternion.identity);
Destroy (effect, 1.0f);
}
} else if (other.gameObject.tag == "Bullet") {
AudioSource.PlayClipAtPoint (noDamageSound, Camera.main.transform.position);
}
}
}

EscapeCombat(メモ)
他のコースを見る

DestroyObjectの改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour {
public GameObject effectPrefab;
public AudioClip effectSound;
void OnCollisionEnter(Collision other){
if (other.gameObject.tag == "Bullet" || other.gameObject.tag == "Rocket") {
Destroy (other.gameObject);
Destroy (gameObject);
AudioSource.PlayClipAtPoint (effectSound, Camera.main.transform.position);
// ★追加
// (ポイント)「foreach」の意味と使い方を調べましょう!
foreach(ContactPoint contactPoint in other.contacts){
// ★修正
// 着弾点をエフェクトの発生位置に指定する。
GameObject effect = (GameObject)Instantiate (effectPrefab, contactPoint.point, Quaternion.identity);
Destroy (effect, 1.0f);
}
}
}
}

DestroyObject2の改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject2 : MonoBehaviour {
public GameObject effectPrefab;
public AudioClip effectSound;
public AudioClip noDamageSound;
void OnCollisionEnter(Collision other){
if (other.gameObject.tag == "Rocket") {
Destroy (other.gameObject);
Destroy (gameObject);
AudioSource.PlayClipAtPoint (effectSound, Camera.main.transform.position);
// ★追加
// (ポイント)「foreach」の意味と使い方を調べましょう!
foreach(ContactPoint contactPoint in other.contacts){
// ★修正
// 着弾点をエフェクトの発生位置に指定する。
GameObject effect = (GameObject)Instantiate (effectPrefab, contactPoint.point, Quaternion.identity);
Destroy (effect, 1.0f);
}
} else if (other.gameObject.tag == "Bullet") {
AudioSource.PlayClipAtPoint (noDamageSound, Camera.main.transform.position);
}
}
}

着弾点でエフェクト発生