Instantiate로 생성된 게임오브젝트는 한마디로 복제품(clone)이다.

이러한 클론들은 프로그램이 Play 도중에는 Hierarchy에 생성이 되었다가 종료하면 사라지 일회성을 갖는다. 

복제품들의 위치정보나 충돌처리를 위해서는 복제품의 Component에 접근을 해야 되는데 이것을 위해 사용하는 것이 바로 as GameObject라던지 as Transform 등이다.


GameObject go = Instantiate(playerprefab, container.transform) as GameObject;
go.GetComponentInChildren<Text>().text = data;


이렇게 하면 clone이 생성돼었을 때 clone의 Component에 접근이 가능하고,

GetComponent를 이용해서 Transform에 접근하거나 다른 Component를 제어할 수 있다. 



Posted by sungho88
,

다양한 숫자 형식(int, long, float 등)에 있는 TryParse 메서드를 사용하여 문자열을 숫자로 변환할 수 있다.


문자열의 시작과 끝에 있는 공백은 무시하지만 

다른 모든 문자는 적절한 숫자 형식(int, long, ulong, float, 10진수 등)을 구성하는 문자여야만 한다.

예를 들어 int.TryParse이면 문자열은 반드시 정수가 들어가야 하는 것이다.


1. Parse 메소드


int numVal = Int32.Parse("-105");

Console.WriteLine(numVal);


의 결과는 Output: -105로 정수로 변환이 되어 출력된다.

 

이것은 그냥 Parse로, 값을 변환해주는 메소드이다.

 

1. TryParse 메소드


int j;

if (Int32.TryParse("-105", out j))

    Console.WriteLine(j);

else

    Console.WriteLine("String could not be parsed."); 


TryParse의 반환값은 bool형이며, 성공적으로 변환되었으면 true가, 그렇지 않으면 false가 반환된다.

out j의 의미는
결과값을 j 변수에 저장하라는 의미이다.
변환이 성공한 경우 32비트 부호 있는 정수 값을 반환하고, 변환이 실패한 경우 0을 반환합니다.

위 예제의 경우


"-105"는 정수형 문자열이므로 정상적으로 변환이 성공하게 된다.

따라서, 결과값은 -105가 될 것이며 이 값이 j변수에 저장된다.


끝-

Posted by sungho88
,

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace ConsoleApplication2

{

    class Program

    {

        static void Main(string[] args)

        {


            Console.WriteLine("Hello 월드!");

            Console.WriteLine("Hello 월드!");

            Console.WriteLine("Hello 월드!");


            Console.Write("Hello");

            Console.Write("Hello");

            Console.Write("Hello");

        }

    }

}


WriteLine() 함수도 텍스트를 출력하는 함수이고,

Write() 함수 역시 동일한 함수이다.


하지만, 차이점은

WriteLine() 함수는 출력한 뒤에 개행이 이뤄지지만,

Write() 함수의 경우 개행되지 않는다.


따라서, 위 예제를 실행하면 결과는 다음과 같다.




Posted by sungho88
,