반응형
환경 설정
1. unity hub 다운로드
2. unity hub 실행 후 계정 생성
3. unity hub 계정으로 로그인 후 unity engine 설치
- install editor 클릭
- official release > LTS(Long-Term Support) 붙은 버전 다운로드
- WebGLBuild Support 선택 (설치 후에도 변경 가능)
4. 설치 완료
프로젝트 설정
1. new project > universal 2D
- new project 클릭
- universal 2D 템플릿 선택 후 project name, location 지정 후 create project
2. 설치 완료
3. assets 다운로드
- 아래 사이트에서 assets 다운로드
- Filter Mode = Point (no filter), Compression = None 으로 설정 후 apply
BackGrounds
1. 3D Object > Quad 생성
2. Quad에 구름 이미지 넣고 Wrap mode = repeat으로 선택
3. Repeat으로 설정 시 Materials 폴더 하위에 이미지 생성됨. 이때 이 이미지의 Tilling의 x축을 2개, y축을 1개로 해서 설정
4. Building의 Surface Type = Transparent, Tilling의 x축 2개, y축 1개로 설정
Scrolling Scripts
using UnityEngine;
public class BackgroundScroll : MonoBehaviour
{
[Header("Settings")]
[Tooltip("How fast the texture scroll speed?")]
public float scrollSpeed;
[Header("References")]
public MeshRenderer meshRenderer;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
meshRenderer.material.mainTextureOffset += new Vector2(scrollSpeed * Time.deltaTime, 0);
}
}
Player Jump
1. player에 Rigidbody 2D, Box Colider 2D추가
2. platform에Box Colider 추가
3. Player Script
using UnityEngine;
public class Player : MonoBehaviour
{
[Header("Settings")]
public float jumpForce;
[Header("References")]
public Rigidbody2D playerRigidBody;
private bool isGrounded = true;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
//playerRigidBody.linearVelocityX = 10;
//playerRigidBody.linearVelocityY = 20;
playerRigidBody.AddForceY(jumpForce, ForceMode2D.Impulse);
isGrounded = false;
}
}
// collision happened
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == "Platform")
{
isGrounded = true;
}
}
}
참고 >>
https://www.youtube.com/watch?v=A58_FWqiekI
반응형