๐ฎUnity
[Unity] ํน๊ฐ ๋ ธํธ
taesooya
2022. 7. 31. 21:43
2021.06.24
1. Life Cycle
- void Awake → OnEnable → Start → Update(ํ๋ฉด์ ๋๋๋ง)
- void FixedUpdate(๊ฐ๊ฒฉ์ ๋ฐ๋ผ ๊ท ์ผํ๊ฒ ํธ์ถ)
- void LateUpdate(update ํจ์์ ๋ก์ง์ด ๋๋ ํ ํธ์ถ)
2. Vector Value
/* ์ ๊ทํ ๋ฒกํฐ Normalized Vector, Unit Vector
* Vector3.forward = Vector3(0,0,1)
* Vector3.up = Vector3(0,1,0)
* Vector3.right = Vector3(1,0,0)
Vector3.one = Vector3(1,1,1)
Vector3.zero = Vector3(0,0,0)
*/
3. Animation
- Legacy - ๊ฐ๋ณ๋ค, Code ์์ฑ
- Mecanim - Visual Editor(Node)
- Generic - 2์กฑ ๋ณดํ์ด ์๋ ๊ฒ
- Humanoid - 2์กฑ ๋ณดํ(Bipal), 15 Bone, Retargetting
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCtrl : MonoBehaviour
{
private float h = 0.0f;
private float v = 0.0f;
private float r = 0.0f;
[Range(5.0f, 20.0f)]
public float moveSpeed = 8.0f;
[Range(100.0f, 200.0f)]
public float turnSpeed = 200.0f;
// Animation ์ปดํฌ๋ํธ๋ฅผ ์ ์ฅํ ๋ณ์๋ฅผ ์ ์ธ
[HideInInspector] // Unity Atrributes
[System.NonSerialized] // C# Attributes
public Animation anim;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animation>(); //Generic Syntax
//anim = this.gameObject.GetComponent("Animation") as Animation
//anim = (Animation)this.gameObject.GetComponent("Animation")
anim.Play("Idle");
}
// Update is called once per fram
void Update()
{
h = Input.GetAxis("Horizontal"); // -1.0f ~ 0.0f ~ +1.0f
v = Input.GetAxis("Vertical"); // -1.0f ~ 0.0f ~ +1.0f
r = Input.GetAxis("Mouse X"); //
Vector3 dir = (Vector3.forward * v) + (Vector3.right * h);
transform.Translate(dir.normalized * Time.deltaTime * moveSpeed);
transform.Rotate(Vector3.up * Time.deltaTime * turnSpeed * r);
**PlayerAnim();**
}
void PlayerAnim()
{
if (v >= 0.1f) // ์ ์ง
{
anim.CrossFade("RunF", 0.3f);
}
else if (v <= -0.1f) // ํ์ง
{
anim.CrossFade("RunB", 0.3f);
}
else if (h >= 0.1f) // ์ค๋ฅธ์ชฝ ์ด๋
{
anim.CrossFade("RunR", 0.3f);
}
else if (h <= -0.1f) // ์ผ์ชฝ์ผ๋ก ์ด๋
{
anim.CrossFade("RunL", 0.3f);
}
else
{
anim.CrossFade("Idle", 0.3f);
}
}
}
© 2021 GitHub
3. Random Value
using Random = UnityEngine.Random;
Random.Range(min, max)
Random.Range(0, 10) ⇒ 0,1,2,...,9
Random.Range(0.0f, 10.0f) ⇒ 00.f,...,10.0f
4. Sky
- skybox (6-sided sky)
- procedural sky
- sky dome
5. Etc.
setactive < meshrendere false true ๊ฐ ๋ ๊ฒฝ์ ์
์ฝ๋ฃจํด - https://docs.unity3d.com/Manual/ExecutionOrder.html
Quaternion ์ฟผํฐ๋์ธ(์ฌ์์)
light map์ ๋์ → static → contribute GI