본문 바로가기
게임 개발 일지/내일배움캠프 TIL

문자열 반환 Substring(n) / fixedDeltatime

by 빛하_ 2023. 12. 11.

 

 

 

알고리즘 코드카타

 

C# 에서 Substring() 메소드를 사용해 문자열 반환하기

 

1. Substring(n) : 문자열에서 인덱스 시작 위치(n)부터 끝까지의 문자열을 반환. (n) 이전의 문자열은 삭제됨.

 

2. Substring(n, m) : 문자열에서 인덱스 시작 위치(n)부터 길이(m)만큼의 문자열을 반환. 

  // Programmers. 핸드폰 번호 가리기
  // 프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.
  // 전화번호가 문자열 phone_number로 주어졌을 때,
  // 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부* 으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.
   
   internal class _027_HidePhoneNums
    {
        public string solution(string phone_number)
        {
            int length = phone_number.Length;
            string remains = new string('*', length - 4) + phone_number.Substring(length - 4);
            return remains;
        }
    }

 

Substring(length - 4); 는 해당 문자열의 뒤 4자리를 남기고 앞자리의 모든 문자를 없애준다.

 

Unity 게임개발 숙련주차 학습내용

 

1.

update 와 fixed update는 서로 다르기 때문에

fixed update에서 deltatime을 사용하고 싶다면 fixedDeltatime 을 사용해야 한다.

 

2.

우리가 사용하는 모든 script (monobehaviour를 상속받고 있는 경우) 의 component들은 behaviour를 상속받고 있다.

그래서 특정 개체를 삭제하는 방법으로

    void OnDeath()
    {
        _rigidbody.velocity = Vector3.zero;

        foreach (Behaviour component in transform.GetComponentsInChildren<Behaviour>())
        {
            component.enabled = false;
        }

        Destroy(gameObject, 2f);
    }

 

이렇게 Behaviour를 불러와서 component를 켜고 끄는 방식을 사용할 수 있다.

 

 

 

 

댓글