본문 바로가기
유니티

6/29 [Invoke, OnBeacmeInvisible(), SoundManger(싱글톤)]

by SUGI_ 2023. 6. 29.

Invoke

   //InvokeRepeating(함수이름,초기지연시간,지연할시간)
        // 2초마다 생성되게 하고 싶다.
        InvokeRepeating("Shoot", 0.5f, 0.5f);

https://chameleonstudio.tistory.com/37

 

유니티 인보크 Invoke 사용법의 모든 것

해당 티스토리 페이지는 필자가 유니티 C# 개발을 하면서 학습한 내용들을 기록하고 공유하는 페이지입니다 ! - 틀린 부분이 있거나, 수정된 부분이 있다면 댓글로 알려주세요 ! - 해당 내용을 공

chameleonstudio.tistory.com

https://iflife1124.tistory.com/16

OnBeacmeInvisible()

    //OnBecameInvisible() 화면밖으로 나가면 안보이게 되면 호출이 되는 함수
    private void OnBecameInvisible()
    {
        //미사일이 화면밖으로 나갔으면?
        //미사일 지우자
        Destroy(gameObject);
    }

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=happybaby56&logNo=221360560066 

 

[유니티] OnBecameVisible(), OnBecameInvisible(), OnWillRenderObject()

void OnBecameVisible() {  }  void OnBecameInvisible() {  }  void OnWillRenderObject() {  }  우선...

blog.naver.com

SoundManger (싱글톤패턴)

public class SoundManger : MonoBehaviour
{
    //싱글톤 -> 전역으로 관리가 쉽다.
    public static SoundManger instance; //자기자신을 변수로 담고

    AudioSource myAudio; //AudioSource 컴포넌트를 변수로 담는다.
    [SerializeField] AudioClip soundExplosion; //재생할 소리를 변수로 담는다.
    [SerializeField] AudioClip soundDie;

    private void Awake() //Start보다도 먼저, 객체가 생성될때 호출된다.
    {
        if(SoundManger.instance == null) //incetance가 비어있는지 검사합니다.
        {
            SoundManger.instance = this; //자기자신을 담는다.
        }
    }

    void Start()
    {
        myAudio = GetComponent<AudioSource>(); //AudioSource 컴포넌트 가져오기    
    }

    public void PlaySound()
    {
        myAudio.PlayOneShot(soundExplosion);
    }

    public void SoundDie()
    {
        myAudio.PlayOneShot(soundDie);
    }
}
        //사운드 사용해보기
        SoundManger.instance.PlaySound();

https://cheershennah.tistory.com/223

 

싱글톤 패턴이란? singleton pattern

싱글톤 패턴이란? singleton pattern 여러 디자인 패턴 종류 중 하나로, 하나의 클래스에 오직 하나의 객체 인스턴스만 가지는 패턴이다. * 디자인 패턴: 프로그램을 설계할때 발생했던 문제점들을 객

cheershennah.tistory.com

 

728x90

'유니티' 카테고리의 다른 글

6/30 [ScoreManager(싱글톤) , 코루틴]  (0) 2023.06.30
6/30 C# 클래스 상속  (0) 2023.06.30
6/28 특정오브젝트 찾기, 인스턴스화  (0) 2023.06.28
6/21 배열 , 형변환  (0) 2023.06.28
6/28 C#  (0) 2023.06.28