C#

C# GetComponent 란?

9D 2017. 5. 24. 17:29
728x90


GetComponent로 다른 오브젝트의 스크립트를 가져올때 사용

오브젝트는 Component가 붙을수 있는 Container역활을 합니다

 

Monobehavoiur를 상속받은 class를 Component라 합니다

 

 void Jump()
 {
  fire.SetActive (true);
  GetComponent<AudioSource>().Play(); //GetComponent 다른 오브젝트 스크립트를 가져올때씀
  GetComponent<Rigidbody2D>().velocity = Vector2.zero;
  GetComponent<Rigidbody2D>().AddForce(Vector2.up * 200);
 }

 

728x90

'C#' 카테고리의 다른 글

C# 형변환 이란?  (0) 2017.07.17
C# 상속 에 대해서  (0) 2017.07.16
C# 접근제한자란?  (0) 2017.07.14
C# if문 if else문  (0) 2017.05.24
C# bool 이란?  (0) 2017.05.24