본문 바로가기

Unity

(48)
1. Player 이동 및 카메라 회전 1. 플레이어 오브젝트의 자식으로 메인 카메라를 넣고 위치를 얼굴 쪽으로 조정한다. Glasses는 카메라가 움직일 때 같이 움직이게 하기 위해 카메라의 자식으로 둔다. 2. 플레이어의 이동을 담당하는 스크립트 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; // 사용자의 입력에 따라 앞뒤좌우로 이동 public class Player : MonoBehaviour { public float speed = 5; void Update() { //사용자의 입력에 따라 float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); //앞뒤좌우..
플레이어 대쉬, 회피 Dash, Dodge Rigidbody rb; // Start is called before the first frame update void Start() { rb = GetComponent(); } public float speed = 5; public float dashSpeed = 20; public float addSpeed; Vector3 finalDir; // Update is called once per frame void Update() { // 추가속력이 없다면(대쉬중이 아니라면) if (addSpeed == 0) { // 입력받은 축을 이용해서 방향을 만들고싶다. float h = Input.GetAxis("Horizontal"); Vector3 dir = Vector3.right * h; // 현재방향을..
프로젝트 1-2 플레이어 대쉬 public class Player : MonoBehaviour { public float speed = 10f; Vector3 dir; bool isDodge; void Update() { float v = Input.GetAxisRaw("Vertical"); float h = Input.GetAxisRaw("Horizontal"); dir = Vector3.right * h + Vector3.forward * v; dir.Normalize(); transform.position += dir * speed * Time.deltaTime; transform.LookAt(transform.position + dir); dodgeKey = Input.GetButton("Dodge"); Dodge(); } v..
프로젝트 1-1 플레이어 이동 using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMove : MonoBehaviour { public float speed = 5f; void Update() { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); Vector3 dir = Vector3.right * h + Vector3.up * v; //dir의 크기가 1이 아닌 경우가 있음 -> 크기를 1로 만들 때 정규화 dir.Normalize(); transform.position += dir * speed * Time.del..
Instantiate public class LeaderBoard : MonoBehaviour { public GameObject goRankBar; public GameObject goLastRankBar; public int count; public Transform rankBarParent; void OnEnable() { for (int i = 0; i < 50; i++) { GameObject rankBar = Instantiate(goRankBar, transform.position, Quaternion.identity); rankBar.transform.SetParent(rankBarParent); if(i == 49) { GameObject lastRankBar = Instantiate(goLastRankBar..
Scroll View 처음 부분부터 보이게 하기 public class MyScoreBoard : MonoBehaviour { public RectTransform a; void OnEnable() { a.anchoredPosition = new Vector2(0, 0); } } a는 Scroll View /View Port 안에 있는 Content를 참조했다. Scroll View 오브젝트가 켜질 때마다 처음 부분부터 보이게 하기 위해 OnEnable 에 작성했다.
유니티 자동 로그인 및 닉네임 생성창 저번 포스팅에서 구글 연동 후 로그인하는 것까지 다뤄봤다. 이번 포스팅은 구글 자동로그인과 닉네임 생성을 하는 것을 다뤄보겠다. 우선 firebase SDK - dotnet4 폴더 안에 있는 FirebaseDatabase.unitypackage를 import 해주자. 유저의 구글ID 과 닉네임을 불러오고, 만약에 닉네임이 없을 때 닉네임을 생성할 수 있는 창을 만들어주기 위해서 데이터베이스를 사용할 것이다. 구글 로그인을 할 때 PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestIdToken() 이 구문으로 IDToken을 요청한다. 아마 이게 로그인할 때 IDToken을 요청한다는 그런 뜻인 것 ..
유니티 구글 연동 방법 1. Firebase SDK import 하기 https://firebase.google.com/docs/unity/setup Unity 프로젝트에 Firebase 추가 Unity 프로젝트에 Firebase 추가plat_iosplat_androidplat_unity Firebase Unity SDK를 활용하여 Unity 게임을 업그레이드 해보세요. Firebase를 Unity 프로젝트에 연결하는 것이 얼마나 간편한지 보여드리기 위해 Google firebase.google.com Firebase unity SDK - dotnet4 폴더 안에 있는 FirebaseAnalytics.unitypackage 와 FirebaseAuth.unitypackage를 유니티에 임포트 시킨다. GPGS 보다 먼저 임포트 ..