Vienna

1일차 본문

유니티/유니티 교과서

1일차

아는개발자 2021. 11. 23. 20:16

오늘부터는 유니티 공부도 병행하기로 했다.

아직까지는 내가 이미 알고 있던 유니티 사용법과 기초적인 프로그래밍 문법에 대해서만 나왔다... 쉽다는 후기가 있긴 했지만 이렇게까지 기초가 나올 줄은 몰랐다. 하지만 앞으로 어려워지겠지. 계속 너무 쉬우면 다른 책을 구매하는 것도 고려해야겠다.

 

Console 창에 띄운 결과는 신기했다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < 5; i++)
            Debug.Log(i);
    }
}

전 회사에서 프로젝트를 실행할 때마다 콘솔창에 멘트 같은 게 떴는데, 이런 식으로 띄우는 거였구나 싶었다. 재밌다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int[] array = new int[5];

        array[0] = 2;
        array[1] = 10;
        array[2] = 5;
        array[3] = 15;
        array[4] = 3;

        for (int i = 0; i < 5; i++)
            Debug.Log(array[i]);
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int[] points = { 83,99,52,93,15};

        for (int i = 0; i < points.Length; i++)
            if(points[i] >= 90)
                Debug.Log(points[i]);
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int[] points = { 83,99,52,93,15};

        int sum = 0;

        for (int i = 0; i < points.Length; i++)
            sum += points[i];

        int avg = sum / points.Length;
        Debug.Log(avg);
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Player myPlayer = new Player();
        myPlayer.Attack();
        myPlayer.Damage(30);
    }
}

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 + "대미지를 입었다!");
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Vector2 playerPos = new Vector2(3.0f, 4.0f);
        playerPos.x += 8.0f;
        playerPos.y += 5.0f;
        Debug.Log(playerPos);
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Vector2 startPos = new Vector2(2.0f, 1.0f);
        Vector2 endPos = new Vector2(8.0f, 5.0f);
        Vector2 dir = endPos - startPos;
        Debug.Log(dir);

        float len = dir.magnitude;
        Debug.Log(len);
    }
}

이제 9시까지 쉬고 알고리즘 공부로 넘어가야겠다.

'유니티 > 유니티 교과서' 카테고리의 다른 글

6일차  (0) 2021.12.03
5일차  (0) 2021.11.30
4일차  (0) 2021.11.29
3일차  (0) 2021.11.25
2일차  (0) 2021.11.24
Comments