티스토리 뷰
서버 관련된걸 강의 영상으로 찍으려고 생각중이다.
지금 생각하고 있는건 여기에 캐릭터 이동하는 거를 Socket.io를 통해 멀티 플레이로 만들 생각이다. 그럴라면 테스트할때 창을 여러개 띠울수 있는게 필요하다.
https://github.com/VeriorPies/ParrelSync/
GitHub - VeriorPies/ParrelSync: (Unity3D) Test multiplayer without building
(Unity3D) Test multiplayer without building. Contribute to VeriorPies/ParrelSync development by creating an account on GitHub.
github.com
그래 이 애드온이 필요하다.
도트 게임이기 때문에 필터를 제거해 준다. 이제 좌우로 움직이는 간단한 메카니즘을 만들어야 한다.
멀티플로 만든다음 잘라준다.
도트 게임을 안만들어서 몰랐는데 이렇게 쉽게 잘라줄수가 있더라.
원래 3D 툴이다보니 애니메이션에서 조금 노가다가 있었다. 여튼 준비는 다 된거 같다. 캐릭터를 움직여 보도록 한다.
using UnityEngine;
namespace Main
{
public class PlayerMove : MonoBehaviour
{
float MoveSpeed => 5f;
Animator AnimatorNode => GetComponent<Animator>();
SpriteRenderer RendererNode => GetComponent<SpriteRenderer>();
int Walk => Animator.StringToHash("Walk");
void Update()
{
float moveInput = Input.GetAxis("Horizontal");
AnimatorNode.SetBool(Walk, moveInput != 0);
RendererNode.flipX = moveInput < 0 ? true : moveInput > 0 ? false : RendererNode.flipX;
transform.position += new Vector3(moveInput * MoveSpeed * Time.deltaTime, 0f, 0f);
}
}
}

의도대로 잘 돌아 간다.
클라이언트는 렌더링만하고 게임 자체는 서버에서 돌아가게 하고 싶지만 Node.js 자체가 그런 게임 기능이 없으니 그건 무리인듯 싶다. 포즈만 받고 클라이언트에게 뿌려주는 것만 만들도록 해야 겠다.
Failed to parse playerSet data: get_gameObject can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
스레드 관련 에러가 뜬다. 자고 일어나서 해결해야 겠다.