๋‚ด ์ธ์ƒ์—์„œ ๋ฏฟ์„ ๊ฑด ์˜ค์ง ๋‚˜ ์ž์‹ ๋ฟ!

The only one you can truly trust is yourself.

๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/์œ ๋‹ˆํ‹ฐ ์—”์ง„(Unity)

์œ ๋‹ˆํ‹ฐ C# ์Šคํฌ๋ฆฝํŠธ ๋ณต์Šต

๐ŸŽฎinspirer9 2022. 8. 30. 22:18
728x90
๋ฐ˜์‘ํ˜•

๋ชฉ์ฐจ

    ์œ ๋‹ˆํ‹ฐ ๊ต๊ณผ์„œ

    • ์œ ๋‹ˆํ‹ฐ ์ฑ…์€ ๋‹ค ๋ฒ„๋ฆฌ๊ณ  ํ•˜๋‚˜ ๋‚จ์•˜๋‹ค.
    • "์œ ๋‹ˆํ‹ฐ ๊ต๊ณผ์„œ"๋ผ๊ณ , ์ž‘๋…„ 2021๋…„ 1์›” 25์ผ ์ถœ๊ฐ„๋œ ์ฑ…์ด๋‹ค.
    • ๋ฒŒ์จ 2022๋…„๋„ ๋ฐ˜ ์ด์ƒ ์ง€๋‚˜๊ฐ”๋Š”๋ฐ ์ด ์ฑ…์„ ์ œ๋Œ€๋กœ ๋๋‚ด์ง€๋ฅผ ์•Š์•˜๋˜ ๊ฒƒ์ด ๊ธฐ์–ต๋‚ฌ๋‹ค.
    • ๊ทธ๋ž˜์„œ ์š”์  ์ •๋ฆฌ๋ฅผ ํ•ด๋ณด๊ธฐ๋กœ ํ•œ๋‹ค.
     

    ์œ ๋‹ˆํ‹ฐ ๊ต๊ณผ์„œ : ๋„ค์ด๋ฒ„ ๋„์„œ

    ๋„ค์ด๋ฒ„ ๋„์„œ ์ƒ์„ธ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

    search.shopping.naver.com

    • ๊ทธ๋Ÿฐ๋ฐ ์ด ์ฑ…์ด ๋‚˜์˜จ์ง€๋„ ์‹œ๊ฐ„์ด ํ˜๋Ÿฌ, ์œ ๋‹ˆํ‹ฐ๊ฐ€ ๋˜ ์—…๊ทธ๋ ˆ์ด๋“œ๊ฐ€ ๋˜์—ˆ๋„ค?
    • ๋ฌผ๋ก  ๋‚ด์šฉ์ด ์™„์ „ํžˆ ํ‹€๋ฆฌ๊ฑฐ๋‚˜ ๋ชป ๋ณด๊ฒ ๋‹ค๋Š” ์˜๋ฏธ๋Š” ์•„๋‹ˆ๋‹ค.
    • ๋‹ค๋งŒ ์ด ์ฑ…์ด ๊ณ„์† ๊ฐœ์ •ํŒ์ด ๋‚˜์˜ค๊ธฐ ๋•Œ๋ฌธ์— ๋นจ๋ฆฌ ์ฝ๊ณ  ์ค‘๊ณ ์„œ์ ์— ํŒ”์•„๋ฒ„๋ ค์•ผ ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋จธ๋ฆฌ ์†์„ ์ง€๋ฐฐํ•œ๋‹ค.

    ์ฑ… ๋‚ด์šฉ

    • ์ด ํฌ์ŠคํŒ…์€ ์œ ๋‹ˆํ‹ฐ ๊ต๊ณผ์„œ ๊ฐœ์ • 4ํŒ์˜ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ๋‹ค.
    • 1์žฅ์€ ๊ธฐ๋ณธ ๊ฐœ๋…์ด๋‹ˆ ๋„˜์–ด๊ฐ€๊ณ , 2์žฅ์€ C# ์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ณธ์ด๋‹ˆ๊นŒ ํ•œ๋ฒˆ ๋ณต์Šตํ•ด๋ณด์ž.
    • ์ฒซ ์‹œ์ž‘๋ถ€ํ„ฐ UnityHub๊ฐ€ ์ถ”๊ฐ€๋˜์–ด ์ €์ž๊ฐ€ ์ž‘์„ฑํ•œ ๋ฐฉ์‹๊ณผ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ๋ฐฉ์‹์ด ๋‹ค๋ฅด๋‹ค.
    • UnityHub ์ถ”๊ฐ€๋œ ๋‹ค์Œ ๋ถ€ํ„ฐ๋Š” empty ํ”„๋กœ์ ํŠธ๋Š” ์ด์ œ ๋ชป ๋งŒ๋“œ๋Š” ๊ฑด๊ฐ€?
    • ์‘ ์•„๋‹ˆ์•ผ.
    • ๋ฐ”๋กœ 2D (core) ํ”„๋กœ์ ํŠธ๋กœ ํ•˜๋‚˜ ์ƒ์„ฑ.
    • ์ดˆ๊ธฐ ์ƒ์„ฑ์ด ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ฆฐ๋‹ค.
    • ์œ ๋‹ˆํ‹ฐ ์—”์ง„์ด ์ ์  ๋ฌด๊ฑฐ์›Œ์ง€๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์ƒˆ์‚ผ ๋Š๋‚„ ์ˆ˜ ์žˆ์—ˆ๋‹ค.
    • ๊ทธ๋ฆฌ๊ณ  ๋นˆ ์˜ค๋ธŒ์ ํŠธ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ ๋งŒ๋“ค๊ณ  GameObject์— ๋„ฃ์–ด์„œ ์ฝ”๋”ฉํ•˜๋ ค๊ณ  ํ–ˆ๋”๋‹ˆ ๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค๋„ ์•ˆ ๊น”์•˜๋„ค?
    • ๊ทธ ์™ธ์—๋„ ๊ฐœ๋ฐœ์šฉ ํฐํŠธ๋ž‘ git, diff/merge ํˆด๋„ ์„ค์น˜ํ•ด์•ผ๊ฒ ๋‹ค. (๋Š” ๋‚˜์ค‘์—)

    External Tools

    • Notepad++๋กœ ์ฝ”๋”ฉํ–ˆ์—ˆ๋Š”๋ฐ, ๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค ์ปค๋ฎค๋‹ˆํ‹ฐ ์„ค์น˜ํ•ด์•ผ ๊ฒ ๋‹ค.
      • ๊ทผ๋ฐ Visual Studio Community 2022 ์„ค์น˜ํ–ˆ๋Š”๋ฐ,
      • ์œ ๋‹ˆํ‹ฐํ—ˆ๋ธŒ๊ฐ€ Visual Studio Community 2019 ์„ค์น˜ํ•ด๋ฒ„๋ฆฌ๋„ค?
      • Visual Studio Code๋„ ๋‹ค์šด๋ฐ›์•˜๋Š”๋ฐ ์„ค์น˜ํ•˜์ง€๋Š” ์•Š์•˜๋‹ค.
    • WinMerge ์„ค์น˜
    • GitHub Desktop ์„ค์น˜

    Source Code

    ๋ชจ๋…ธ ๋น„ํ—ค์ด๋น„์–ด ๊ธฐ๋ณธ, ๋ณ€์ˆ˜, ๋ฌธ์ž์—ด, ๋””๋ฒ„๊ทธ ๋กœ๊ทธ ์ถœ๋ ฅ

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Test : MonoBehaviour
    {
        // ํด๋ž˜์Šค ๋ณ€์ˆ˜ ๊ฐ™์€ ๊ฑฐ ์ถ”๊ฐ€
        int age;
        float f;
        double dd;
        bool bTrue;
        char z;
        string text1;
        string text2;
        
        void Start() // ์ฒซ๋ฒˆ ์งธ ํ”„๋ ˆ์ž„ ๋ฐ”๋กœ ์ „์— ํ˜ธ์ถœ๋จ.
        {
            age = 45;
            
            text1 = "๋””๋ฒ„๊ทธ";
            text2 = "๋กœ๊ทธ";
            Debug.Log(text1 + text2 + age);
        }
    
        void Update() // ํ”„๋ ˆ์ž„๋งˆ๋‹ค ํ•œ๋ฒˆ ์”ฉ ํ˜ธ์ถœ๋จ. ํ”„๋ ˆ์ž„ ๊ฐ„๊ฒฉ์€ Time.deltaTime ๊ฐ’์— ๋Œ€์ž…๋จ.
        {
            age++;
            //Debug.Log(age);
        }
    }

    ์ œ์–ด๋ฌธ, if, else, for

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Test : MonoBehaviour
    {
        int a = 1;
    
        void Start() // ์ฒซ๋ฒˆ ์งธ ํ”„๋ ˆ์ž„ ๋ฐ”๋กœ ์ „์— ํ˜ธ์ถœ๋จ.
        {
            for(int i=0;i<10;i++){
                a++;
            }
            
            if(a >= 10){
                Debug.Log("๋งž์Œ");
            }else{
                Debug.Log("ํ‹€๋ฆผ");
            }
        }
    
        void Update() // ํ”„๋ ˆ์ž„๋งˆ๋‹ค ํ•œ๋ฒˆ ์”ฉ ํ˜ธ์ถœ๋จ. ํ”„๋ ˆ์ž„ ๊ฐ„๊ฒฉ์€ Time.deltaTime ๊ฐ’์— ๋Œ€์ž…๋จ.
        {
            a++;
        }
    }

    ๋ฐฐ์—ด

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Test : MonoBehaviour
    {
        int[] score = { 99, 98, 97, 100, 20 };
        int[] array = new int[5];
    
        void Start() // ์ฒซ๋ฒˆ ์งธ ํ”„๋ ˆ์ž„ ๋ฐ”๋กœ ์ „์— ํ˜ธ์ถœ๋จ.
        {
            for(int i=0;i<5;i++)
            {
                array[i] = score[i];
            }
            
            for(int i=0; i<array.Length; i++)
            {
                if(array[i] < 100) Debug.Log(array[i]);
            }
        }
    
        void Update() // ํ”„๋ ˆ์ž„๋งˆ๋‹ค ํ•œ๋ฒˆ ์”ฉ ํ˜ธ์ถœ๋จ. ํ”„๋ ˆ์ž„ ๊ฐ„๊ฒฉ์€ Time.deltaTime ๊ฐ’์— ๋Œ€์ž…๋จ.
        {
        }
    }

    ๋ฉ”์„œ๋“œ ๋งŒ๋“ค๊ธฐ

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Test : MonoBehaviour
    {
        int AddAge()
        {
            return 99;
        }
        
        void SayHello(string name)
        {
            Debug.Log("Hello" + name + AddAge());
        }
        
        void Start() // ์ฒซ๋ฒˆ ์งธ ํ”„๋ ˆ์ž„ ๋ฐ”๋กœ ์ „์— ํ˜ธ์ถœ๋จ.
        {
            string n = "๋‹ค์ด๊ณ ๋กœ";
            
            SayHello(n);
        }
        
        void Update() // ํ”„๋ ˆ์ž„๋งˆ๋‹ค ํ•œ๋ฒˆ ์”ฉ ํ˜ธ์ถœ๋จ. ํ”„๋ ˆ์ž„ ๊ฐ„๊ฒฉ์€ Time.deltaTime ๊ฐ’์— ๋Œ€์ž…๋จ.
        {
        }
    }

    ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Player
    {
        private int hp = 100;
        private int power = 50;
        
        public void Attack()
        {
            Debug.Log(this.power + "๋Œ€๋ฏธ์ง€๋ฅผ ์ž…ํ˜”๋‹ค.");
        }
        
        public void Damage(int damage)
        {
            this.hp -= damage;
            Debug.Log(damage + "๋Œ€๋ฏธ์ง€๋ฅผ ์ž…์—ˆ๋‹ค.");
        }
    }
    
    public class Test : MonoBehaviour
    {    
        void Start() // ์ฒซ๋ฒˆ ์งธ ํ”„๋ ˆ์ž„ ๋ฐ”๋กœ ์ „์— ํ˜ธ์ถœ๋จ.
        {
            Player myPlayer = new Player();
            myPlayer.Attack();
            myPlayer.Damage(30);
        }
        
        void Update() // ํ”„๋ ˆ์ž„๋งˆ๋‹ค ํ•œ๋ฒˆ ์”ฉ ํ˜ธ์ถœ๋จ. ํ”„๋ ˆ์ž„ ๊ฐ„๊ฒฉ์€ Time.deltaTime ๊ฐ’์— ๋Œ€์ž…๋จ.
        {
        }
    }

    ๋ฒกํ„ฐ(Vector) ์‚ฌ์šฉํ•˜๊ธฐ

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Test : MonoBehaviour
    {    
        void Start() // ์ฒซ๋ฒˆ ์งธ ํ”„๋ ˆ์ž„ ๋ฐ”๋กœ ์ „์— ํ˜ธ์ถœ๋จ.
        {
            //Vector3์™€ Vector2๊ฐ€ ์žˆ๋„ค?
            Vector2 playerPos = new Vector2(3.0f, 4.0f);
            playerPos.x += 8.0f;
            playerPos.y += -5.0f;
            
            Vector2 enemyPos = new Vector2(20.0f, 9.0f);
            Vector2 dir = enemyPos - playerPos;
            
            Debug.Log(playerPos);
            Debug.Log(dir);
            
            float len = dir.magnitude;
            Debug.Log(len);
        }
    }

    ๋

    • 2์žฅ์˜ ๋‚ด์šฉ์€ ์ด๋ ‡๊ฒŒ ๋.
    • ์ƒ๊ฐ๋ณด๋‹ค ๋ณต์žกํ•˜์ง€ ์•Š์•„์„œ ์ดˆ๋ณด์ž ์šฉ์œผ๋กœ ๋”ฑ์ด๋‹ค.
    • ๋ฏธ๋‹ˆ ๊ฒŒ์ž„ ๋งŒ๋“ค๊ธฐ์— ํ•„์š”ํ•œ ์ •๋„๋กœ ๋๋‚˜์„œ ๋‹คํ–‰์ด๋ผ๋Š” ์ƒ๊ฐ์ด๋‹ค.
    • ์œ ๋‹ˆํ‹ฐ๋ฅผ ๋” ๊นŠ๊ฒŒ ๋ฐฐ์šฐ๊ณ  ์‹ถ์ง€๋Š” ์•Š๊ธฐ ๋•Œ๋ฌธ...;;;
    728x90
    ๋ฐ˜์‘ํ˜•