障害物を破壊する(2)
![E3241670 ee57 45d7 8a95 83c9a7529428](https://codegenius.org/uploads/slide/image/2773/e3241670-ee57-45d7-8a95-83c9a7529428.jpeg)
![263f9151 0c27 4ab6 867d 54ae1f91fadf](https://codegenius.org/uploads/slide/image/2774/263f9151-0c27-4ab6-867d-54ae1f91fadf.jpeg)
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){
// (復習)「else if」の意味を復習しましょう!
if (other.gameObject.tag == "Rocket") {
Destroy (other.gameObject);
Destroy (gameObject);
AudioSource.PlayClipAtPoint (effectSound, Camera.main.transform.position);
GameObject effect = (GameObject)Instantiate (effectPrefab, transform.position, Quaternion.identity);
Destroy (effect, 1.0f);
} else if (other.gameObject.tag == "Bullet") {
// 弾がはねかえれる音を出す。
AudioSource.PlayClipAtPoint (noDamageSound, Camera.main.transform.position);
}
}
}
![5a55477b b9d7 4629 96f4 36efaa3a1cad](https://codegenius.org/uploads/slide/image/2775/5a55477b-b9d7-4629-96f4-36efaa3a1cad.jpeg)
![Ebac412e fb9f 4d49 9f0b b20c77b759e7](https://codegenius.org/uploads/slide/image/2776/ebac412e-fb9f-4d49-9f0b-b20c77b759e7.jpeg)
EscapeCombat(メモ)
他のコースを見る![E3241670 ee57 45d7 8a95 83c9a7529428](https://codegenius.org/uploads/slide/image/2773/e3241670-ee57-45d7-8a95-83c9a7529428.jpeg)
![263f9151 0c27 4ab6 867d 54ae1f91fadf](https://codegenius.org/uploads/slide/image/2774/263f9151-0c27-4ab6-867d-54ae1f91fadf.jpeg)
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){
// (復習)「else if」の意味を復習しましょう!
if (other.gameObject.tag == "Rocket") {
Destroy (other.gameObject);
Destroy (gameObject);
AudioSource.PlayClipAtPoint (effectSound, Camera.main.transform.position);
GameObject effect = (GameObject)Instantiate (effectPrefab, transform.position, Quaternion.identity);
Destroy (effect, 1.0f);
} else if (other.gameObject.tag == "Bullet") {
// 弾がはねかえれる音を出す。
AudioSource.PlayClipAtPoint (noDamageSound, Camera.main.transform.position);
}
}
}
![5a55477b b9d7 4629 96f4 36efaa3a1cad](https://codegenius.org/uploads/slide/image/2775/5a55477b-b9d7-4629-96f4-36efaa3a1cad.jpeg)
![Ebac412e fb9f 4d49 9f0b b20c77b759e7](https://codegenius.org/uploads/slide/image/2776/ebac412e-fb9f-4d49-9f0b-b20c77b759e7.jpeg)
障害物を破壊する(2)