μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- μκ³ λ¦¬μ¦μμ -λλΉμ°μ νμ2
- KRAFTON JUNGLE
- μ λν°
- anonymous page
- μ°κ²°λ¦¬μ€νΈ
- μΆμν΄λμ€μμΈν°νμ΄μ€
- BFS
- User Stack
- pintos
- μ μ-μ ν¬
- μκ³ λ¦¬μ¦
- λ°±μ€
- λ€μ΅μ€νΈλΌ
- ν¬λνν€μ κΈ
- TiL
- C
- ν¬λνν€μ κΈ4κΈ°
- λ€νΈμν¬
- kraftonjungle
- ν°μ€ν 리μ±λ¦°μ§
- c#
- project3
- 4κΈ°
- ν¬λνν€ μ κΈ 4κΈ°
- νμ΄μ¬
- μ΄λ²€νΈ ν¨μ μ€ν μμ
- μ€λΈμ
- νν μ€
- ν¬λνν€ μ κΈ
- Unity
- Today
- Total
λ§κ°λ‘κ·Έ
ν¬λνν€ μ κΈ WEEK12 DAY 93 - μ λν° ν°μΉ ν¨λλ‘ μΉ΄λ©λΌ μ‘°μ & μ λλ©μ΄μ μ μ© λ³Έλ¬Έ
ν¬λνν€ μ κΈ WEEK12 DAY 93 - μ λν° ν°μΉ ν¨λλ‘ μΉ΄λ©λΌ μ‘°μ & μ λλ©μ΄μ μ μ©
habbn 2024. 4. 8. 22:46π2024.04.08
1. μ λν° ν°μΉ ν¨λλ‘ μΉ΄λ©λΌ μ‘°μ & μ λλ©μ΄μ μ μ©
2. UnityYAMLMerge μ€μΉ
3. λ°±μ€
μ΄μ μΉ΄λ©λΌ νμ μ΄ νλ μ΄μ΄ μ€μ¬μΌλ‘ μλκ³ μν μΉ΄λ©λΌ λ§λ₯ μ‘°μλμ΄μ μ€λ λ€μ μ λλ‘ μμ νμλ€.
μ΄ λΆ μ νλΈλ₯Ό 보면μ μ°Έκ³ νμλ€.
https://www.youtube.com/watch?v=4611qmBWTC0
MainCamera.cs
using UnityEngine;
public class MainCamera : MonoBehaviour
{
public Transform target;
public float followspeed = 15f; //λ°λΌκ°λ μλ
public float sensitive = 7f; //κ°λ
public float clampAngle = 50f; //μΉ΄λ©λΌ νμ κ°λμ μ ν
private float rotX;
private float rotY;
public Transform realCamera;
public Vector3 dirNormalized; //λ°©ν₯벑ν°
public Vector3 finalDir; //μ΅μ’
λ°©ν₯
public float minDistance; //μ΅μ 거리
public float maxDistance; //μ΅λ 거리
public float finalDistance; //μ΅μ’
거리
public float smoothness = 10f;
public FixedTouchField touchField;
public bool enableMobile = false;
void Start()
{
rotX = transform.localRotation.eulerAngles.x;
rotY = transform.localRotation.eulerAngles.y;
dirNormalized = realCamera.localPosition.normalized;
//magnitudeλ 벑ν°μ κΈΈμ΄(ν¬κΈ°)λ₯Ό λ°ννλ λ©μλ
finalDistance = realCamera.localPosition.magnitude;
}
void Update()
{
if (enableMobile)
{
rotY += touchField.TouchDist.x * sensitive * Time.deltaTime;
rotX -= touchField.TouchDist.y * sensitive * Time.deltaTime;
}
else
{
rotY += Input.GetAxis("Mouse X") * sensitive * Time.deltaTime;
rotX -= Input.GetAxis("Mouse Y") * sensitive * Time.deltaTime;
}
rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle); //κ°λμ λ²μ
Quaternion rot = Quaternion.Euler(rotX, rotY, 0); //μΉ΄λ©λΌμ νμ
transform.rotation = rot;
}
void LateUpdate()
{
transform.position = Vector3.Lerp(transform.position, target.position, followspeed * Time.deltaTime);
//transform.TransformPoint() λ‘컬 μ’νκ³μμ μ§μ λ μ§μ μ μλ μ’νκ³λ‘ λ³ν
finalDir = transform.TransformPoint(dirNormalized * maxDistance);
RaycastHit hit;
//μΉ΄λ©λΌμ νμ¬ μμΉμ μ΅μ’
μμΉ μ¬μ΄μ μ₯μ λ¬Όμ΄ μλμ§ κ²μ¬
//μ₯μ λ¬Όμ΄ μμΌλ©΄ hit λ³μμ μ λ³΄κ° μ μ₯
if(Physics.Linecast(transform.position, finalDir, out hit))
{
//minDistanceμ maxDistance μ¬μ΄μ κ°μ μ μ§νλλ‘ κ±°λ¦¬λ₯Ό Clampν¨
finalDistance = Mathf.Clamp(hit.distance, minDistance, maxDistance);
}
else
{
finalDistance = maxDistance;
}
//Lerp ν¨μλ₯Ό μ¬μ©νμ¬ μ€μ μΉ΄λ©λΌμ λ‘컬 μμΉλ₯Ό λ°©ν₯ 벑ν°μ μ΅μ’
거리μ λ§κ² λΆλλ½κ² μ΄λ
realCamera.localPosition = Vector3.Lerp(realCamera.localPosition, dirNormalized * finalDistance, Time.deltaTime * smoothness);
}
}
Mathf.Clamp ν¨μλ μ£Όμ΄μ§ κ°μ λ²μλ₯Ό μ§μ λ μ΅μκ°κ³Ό μ΅λκ° μ¬μ΄λ‘ μ ννλλ° μ¬μ©λλ€.
TransformPoint() ν¨μλ λ‘컬 μ’νκ³μμ μ§μ λ μ§μ μ μλ μ’νκ³λ‘ λ³ννλλ° μ¬μ©λλ€.
public Vector3 TransformPoint(Vector3 position);
• positionμ νμ¬ κ°μ²΄μ λ‘컬 μ’νκ³μμμ μμΉ
• TransformPointλ ν΄λΉ μ§μ μ μλ μ’νκ³λ‘ λ³ννμ¬ λ°ννλ€.
μ΄ λ©μλλ μ£Όλ‘ κ°μ²΄μ λ‘컬 μ’νκ³μμ νΉμ μ§μ μ μλ μ’νκ³λ‘ λ³νν λ μ¬μ©λλ€. μ£Όλ‘ νΉμ μ§μ μ μ λ μμΉλ₯Ό μ»κ±°λ, ν΄λΉ μ§μ μ λ€λ₯Έ κ°μ²΄μ 곡κ°μμ μ¬μ©ν λ μ μ©νλ€.
κ·Έλ¦¬κ³ λ°λ°ν νλ μ΄μ΄ μ΄λμ μ λλ©μ΄μ μ μ νμ£Όμλ€.
PlayerController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public bool enableMobile = false;
[SerializeField]
private float smoothRotationTime; //target κ°λλ‘ νμ νλλ° κ±Έλ¦¬λ μκ°
[SerializeField]
private float smoothMoveTime; //target μλλ‘ λ°λλλ° κ±Έλ¦¬λ μκ°
[SerializeField]
private float moveSpeed;
private float rotationVelocity;
private float speedVelocity;
private float currentSpeed;
private float targetSpeed;
Transform cameraTransform;
public VariableJoystick joystick;
Animator anim;
void Awake()
{
anim = GetComponent<Animator>();
cameraTransform = Camera.main.transform;
}
void Update()
{
Vector2 input = Vector2.zero;
if (enableMobile)
{
input = new Vector2(joystick.input.x, joystick.input.y);
}
else
{
input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}
anim.SetBool("IsWalk", input != Vector2.zero);
Vector2 inputDir = input.normalized;
//μμ§μμ λ©μ·μ λ λ€μ μ²μ κ°λλ‘ λμκ°λ κ±Έ λ§κΈ° μν¨
if (inputDir != Vector2.zero)
{
float rotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg + cameraTransform.eulerAngles.y;
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, rotation, ref rotationVelocity, smoothRotationTime);
}
//μ
λ ₯ λ°©ν₯μ λ°λ₯Έ λͺ©ν μλ
targetSpeed = moveSpeed * inputDir.magnitude;
//νμ¬ μλλ₯Ό λͺ©ν μλλ‘ λΆλλ½κ² μ‘°μ
currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedVelocity, smoothMoveTime);
//νμ¬ μ€νΌλμμ νκ² μ€νΌλκΉμ§ smoothMoveTime λμ λ³νλ€.
transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World);
}
void OnTriggerStay(Collider other) {
if (other.gameObject.tag == "NoticeBoard") {
Debug.Log("NoticeBoard");
}
}
}
νμ¬κΉμ§ νλ μ΄μ΄ μ΄λ & μΉ΄λ©λΌ νμ μ μλ£λ μνμ΄λ€~
μΆκ°λ‘ λ‘κ·ΈμΈ & νμκ°μ & μΊλ¦ν° μ ν μ°½μ κ°μ νμμ΄ μΊλ¦¬ν΄λ²λ €μ
λ΄μΌλΆν° κ²μν μμ± λΆλΆ ꡬν κ³νμ΄λ€.
λ°±μ€
μμ κ²½λ‘ λ¬Έμ λ₯Ό νλ €κ³ νλλ μλΌν μ€ν λ€μ€μ 체λ₯Ό μμμΌ νλ€κ³ ν΄μ μλΌν μ€ν λ€μ€μ 체 곡λΆλ₯Ό νμλ€.
μλΌν μ€ν λ€μ€μ 체λ λ€μμ μμ°μμ λνμ¬ μμ μ¬λΆλ₯Ό νλ³ν λ μ¬μ©νλ λνμ μΈ μκ³ λ¦¬μ¦μ΄λ€.