障害物を破壊する(2)


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);
}
}
}


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

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);
}
}
}


障害物を破壊する(2)