using UnityEngine;

using System.Collections;


public class Sparks : 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;

                Expolosion();

            }

        }

    }

            void Expolosion()

            {

                audio.PlayOneShot(secondSound, 1.0f);

                gameObject.AddComponent<Rigidbody>();

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


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


                Destroy(newSpark2, 5.0f);

            Destroy(gameObject, 0.2f);

            }

        }


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

Bullet  (0) 2013.08.06
MyGizmo.cs  (0) 2013.08.06
bulletCtrl  (0) 2013.07.25
PlayerCtrl_V2  (0) 2013.07.25
PlayerCrtl  (0) 2013.07.25

+ Recent posts