using UnityEngine;

using System.Collections;


public class Spark : MonoBehaviour {


public GameObject firstSpark;   

public GameObject secondSpark;

public AudioClip firstSound;

public AudioClip secondSound;

private int hit = 0;

void OnCollisionEnter(Collision Col)

{

if(Col.gameObject.tag == "Bullet")

{

hit++;

audio.PlayOneShot(firstSound, 1.0f);

GameObject newSpark1 = (GameObject)Instantiate(firstSpark, Col.transform.position, Quaternion.LookRotation(-Col.transform.position));

Destroy(newSpark1, 3.0f);

Destroy(Col.gameObject);

if(hit >=3)

{

GetComponent<CapsuleCollider>().enabled = false;

Explosion();

}

}

}

void Explosion()

{

audio.PlayOneShot(secondSound, 1.0f);

gameObject.AddComponent<Rigidbody>();

GameObject newSpark2 = (GameObject)Instantiate (secondSpark,transform.position,Quaternion.identity);

GetComponent<Rigidbody>().AddForce(Vector3.up * 1000.0f);

Destroy(newSpark2,5.0f);

Destroy(gameObject,0.2f);

}

}


'유니티3D > 예제' 카테고리의 다른 글

MonsterCtrl.cs  (0) 2013.08.12
메카님방식  (0) 2013.08.12
miniMap  (0) 2013.08.07
PlayerCtrl  (0) 2013.08.06
Bullet  (0) 2013.08.06

+ Recent posts