728x90
반응형
4. 캐릭터 움직이기
-
- 먼저 세팅하기 : Visual Studio
- 윈) Edit → Preferences → External Tools → Visual Studio Community 2019로 맞추기
- 맥) Unity → Preferences → External Tools → Visual Studio for mac
-
- 캐릭터에 코딩을 더하는 법
- → 즉, 캐릭터에 코드를 입히는 것. "너는 태어날 때 여기서 태어나고, 매 순간 이렇게 작동해라"
-
- Script 만들기
- → C#은? Microsoft가 개발한 코딩 개발 언어. 희한하게 유니티에서만 주류로 쓰이고 있다.
-
- 캐릭터 좌우 움직임 코딩하기
-
- 캐릭터 오른쪽으로 이동하기
- [코드스니펫] 캐릭터 오른쪽으로 이동하기
- void Update() { transform.position += new Vector3(0.05f, 0, 0); }
→ Play 버튼을 눌러보기 (캐릭터가 오른쪽으로 이동한다!)→ transform의 의미: 캐릭터의 위치와 중, position을 계속 바꿔달라는 것→ 트랜스폼 안의 포지션을, Vector3 방향으로 계속 더해주세요→ 위에 변수를 선언해서 이렇게 쓸 수도 있음!void Update() { transform.position += new Vector3(0.05f, 0, 0); }
- float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { transform.position += new Vector3(direction, 0, 0); }
- → float 란? 소수점을 나타내는 자료형. 즉, 소수를 쓰고 싶으면 뒤에 f 를 붙여줘야 함
- → transform.position += new Vector3(0.05f, 0, 0);
-
- 캐릭터가 벽에 닿으면 다른 방향을 보게 하기
- [코드스니펫] Debug.log
- Debug.Log(transform.position.x);
C#Debug.Log(transform.position.x);
- [코드스니펫] 760보다 클 때 다른 방향 보게 하기
- float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (transform.position.x > 2.8f) { direction = -0.05f; } transform.position += new Vector3(direction, 0, 0); }
→ 2-2) 0보다 작을 때 다른 방향 보게 하기float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (transform.position.x > 2.8f) { direction = -0.05f; } transform.position += new Vector3(direction, 0, 0); }
- → 2-1) 760보다 클 때 다른 방향 보게 하기
4. 캐릭터 움직이기
-
- 먼저 세팅하기 : Visual Studio
- 윈) Edit → Preferences → External Tools → Visual Studio Community 2019로 맞추기
- 맥) Unity → Preferences → External Tools → Visual Studio for mac
-
- 캐릭터에 코딩을 더하는 법
- → 즉, 캐릭터에 코드를 입히는 것. "너는 태어날 때 여기서 태어나고, 매 순간 이렇게 작동해라"
-
- Script 만들기
- → C#은? Microsoft가 개발한 코딩 개발 언어. 희한하게 유니티에서만 주류로 쓰이고 있다.
-
- 캐릭터 좌우 움직임 코딩하기
-
- 캐릭터 오른쪽으로 이동하기
- [코드스니펫] 캐릭터 오른쪽으로 이동하기
- void Update() { transform.position += new Vector3(0.05f, 0, 0); }
→ Play 버튼을 눌러보기 (캐릭터가 오른쪽으로 이동한다!)→ transform의 의미: 캐릭터의 위치와 중, position을 계속 바꿔달라는 것→ 트랜스폼 안의 포지션을, Vector3 방향으로 계속 더해주세요→ 위에 변수를 선언해서 이렇게 쓸 수도 있음!void Update() { transform.position += new Vector3(0.05f, 0, 0); }
- float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { transform.position += new Vector3(direction, 0, 0); }
- → float 란? 소수점을 나타내는 자료형. 즉, 소수를 쓰고 싶으면 뒤에 f 를 붙여줘야 함
- → transform.position += new Vector3(0.05f, 0, 0);
-
- 캐릭터가 벽에 닿으면 다른 방향을 보게 하기
- [코드스니펫] Debug.log
- Debug.Log(transform.position.x);
C#Debug.Log(transform.position.x);
- [코드스니펫] 760보다 클 때 다른 방향 보게 하기
- float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (transform.position.x > 2.8f) { direction = -0.05f; } transform.position += new Vector3(direction, 0, 0); }
→ 2-2) 0보다 작을 때 다른 방향 보게 하기float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (transform.position.x > 2.8f) { direction = -0.05f; } transform.position += new Vector3(direction, 0, 0); }
- → 2-1) 760보다 클 때 다른 방향 보게 하기
4. 캐릭터 움직이기
-
- 먼저 세팅하기 : Visual Studio
- 윈) Edit → Preferences → External Tools → Visual Studio Community 2019로 맞추기
- 맥) Unity → Preferences → External Tools → Visual Studio for mac
-
- 캐릭터에 코딩을 더하는 법
- → 즉, 캐릭터에 코드를 입히는 것. "너는 태어날 때 여기서 태어나고, 매 순간 이렇게 작동해라"
-
- Script 만들기
- → C#은? Microsoft가 개발한 코딩 개발 언어. 희한하게 유니티에서만 주류로 쓰이고 있다.
-
- 캐릭터 좌우 움직임 코딩하기
-
- 캐릭터 오른쪽으로 이동하기
- [코드스니펫] 캐릭터 오른쪽으로 이동하기
- void Update() { transform.position += new Vector3(0.05f, 0, 0); }
→ Play 버튼을 눌러보기 (캐릭터가 오른쪽으로 이동한다!)→ transform의 의미: 캐릭터의 위치와 중, position을 계속 바꿔달라는 것→ 트랜스폼 안의 포지션을, Vector3 방향으로 계속 더해주세요→ 위에 변수를 선언해서 이렇게 쓸 수도 있음!void Update() { transform.position += new Vector3(0.05f, 0, 0); }
- float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { transform.position += new Vector3(direction, 0, 0); }
- → float 란? 소수점을 나타내는 자료형. 즉, 소수를 쓰고 싶으면 뒤에 f 를 붙여줘야 함
- → transform.position += new Vector3(0.05f, 0, 0);
-
- 캐릭터가 벽에 닿으면 다른 방향을 보게 하기
- [코드스니펫] Debug.log
- Debug.Log(transform.position.x);
C#Debug.Log(transform.position.x);
- [코드스니펫] 760보다 클 때 다른 방향 보게 하기
- float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (transform.position.x > 2.8f) { direction = -0.05f; } transform.position += new Vector3(direction, 0, 0); }
→ 2-2) 0보다 작을 때 다른 방향 보게 하기float direction = 0.05f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (transform.position.x > 2.8f) { direction = -0.05f; } transform.position += new Vector3(direction, 0, 0); }
- → 2-1) 760보다 클 때 다른 방향 보게 하기
728x90
반응형
'코딩공부' 카테고리의 다른 글
리액트 기초 지식 (0) | 2022.10.20 |
---|---|
어바웃 화면 만들기 (0) | 2022.10.13 |
자바스크립트 -딕셔너리 키와 값을 빠르게 꺼내기! - 비구조 할당 (0) | 2022.10.12 |
프론트엔드? 백엔드? 어떤 차이가 있을까요? (0) | 2022.08.15 |
JAVA 소개 (0) | 2020.04.24 |
댓글