본문 바로가기

유니티(Unity)

Webgl 로컬에서 실행시키기(Express)

Unity에서 webgl 빌드 후, 빌드 된 파일을 로컬 서버로 실행.(Webgl은 비압축 형태로 빌드)

vscode에서 프로젝트 폴더를 만들고 express설치.

 

이 프로젝트 폴더에 webgl파일들을 넣어야 하는데,

빌드된 파일들을 "WebGLTEST" 이라는 폴더에 담고, vscode 프로젝트 폴더에 넣는다.

 

서버측 코드

const express = require("express");
const app = express();
const http = require("http")
const path = require("path");

const port = 8000;
app.use(express.static(path.join(__dirname, "/WebGLTEST")));
app.get("/", (req, res) =>{
    res.sendFile(path.join(__dirname, "WebGLTEST", "index.html"));
})
http.createServer(app).listen(port, () => {
    console.log(`Server runiing ${port}`)
})

 

 

주소창에 "localhost:8000" 으로 접속하면 잘 실행된다.

 

참고자료:

https://tycovds.medium.com/build-a-unity-webgl-game-and-serve-it-with-an-express-server-771e60267e10