๐ŸŽฎ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

  1. skybox (6-sided sky)
  2. procedural sky
  3. sky dome

 

5. Etc.

setactive < meshrendere false true ๊ฐ€ ๋” ๊ฒฝ์ œ์ 
์ฝ”๋ฃจํ‹ด - https://docs.unity3d.com/Manual/ExecutionOrder.html
Quaternion ์ฟผํ„ฐ๋‹ˆ์–ธ(์‚ฌ์›์ˆ˜)
light map์˜ ๋Œ€์ƒ → static → contribute GI