본문 바로가기

unity26

[Unity | 유니티] 하트 충전 스크립트(로컬 디바이스 시간 기준) 디바이스의 로컬 시간을 기준으로 특정 시간 간격으로 하트 갯수를 충전하는 스크립트이다. 유저가 마지막으로 게임을 이탈, 종료했던 시간을 저장해 두었다가, 게임에 재진입 했을 때 이탈 했던 시간과 현재의 시간차를 계산하여 하트를 충전해 주고. 만약 하트가 최대값이 아니라면 타이머를 돌려 계속 하트가 충전되도록 한다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77.. 2019. 10. 11.
[Unity | 유니티] OnApplicationFocus(bool value) vs. OnApplicationPause(bool value) 디바이스에서 게임을 직접적으로 종료하지 않고 이탈/복귀하는 경우 OnApplicationFocus(bool value)와 OnApplicationPause(bool value)가 실행된다. 이 두 함수의 차이는 다음과 같다. 게임이 처음 실행될 때 OnApplicationFocus(true)가 호출된다. (동일 스크립트 상의 Awake() 실행 이후, Start() 실행 전에 호출) 플레이 도중 게임을 이탈했을 때(홈버튼을 누르거나 다른 앱을 사용하게 되었을 때) OnApplicationFocus(false)가 호출된다. OnApplicationPause(true)가 호출된다. 이탈했던 게임에 다시 복귀했을 때 OnApplicationFocus(true)가 호출된다. OnApplicationPause(f.. 2019. 10. 8.
[C#] C# string.Replace 메서드 public string Replace (char oldChar, char newChar); oldChar를 newChar로 치환하여 반환한다. oldChar가 없으면 기존 값을 반환한다. 현재의 인스턴스 값은 수정되지 않는다. using System; public class Example { public static void Main() { String s = new String('a', 3); Console.WriteLine("The initial string: '{0}'", s); s = s.Replace('a', 'b').Replace('b', 'c').Replace('c', 'd'); Console.WriteLine("The final string: '{0}'", s); } } [결과] The .. 2019. 9. 26.
[C#] C# string.Substring 메서드 public string Substring (int startIndex); 인스턴스에서 startIndex부터 마지막까지의 부분 문자열을 검색한다. 현재의 인스턴스 값은 수정되지 않는다. *인덱스는 0부터 시작한다. using System; public class Example { public static void Main() { String[] pairs = { "Color1=red", "Color2=green", "Color3=blue", "Title=Code Repository" }; foreach (var pair in pairs) { int position = pair.IndexOf("="); if (position < 0) continue; Console.WriteLine("Key: {0}, .. 2019. 9. 26.