Crazy Lazy

[1일차] C# Script 과제 본문

Unity/선행학습

[1일차] C# Script 과제

Crazy Lazy 2025. 9. 9. 10:26
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 SayHello()
    {
        Debug.Log("Hello");
    }

    void CallName(string name)
    {
        Debug.Log("Hello " + name);
    }

    int Add(int a, int b)
    {
        int c = a + b;
        return c;
    }
    
    // Start is called before the first frame update
    void Start()
    {
        // Debug.Log("Hello World!");
        
        // int age;
        // age = 30;
        // Debug.Log(age);

        // float heigth1 = 160.5f;
        // float heigth2;
        // heigth2 = heigth1;
        // Debug.Log(heigth2);

        // string name;
        // name = "Sera";
        // Debug.Log(name);

        // int answer;
        // answer = 1 + 2;
        // Debug.Log(answer);

        // int answer;
        // answer = 3 - 4;
        // Debug.Log(answer);
        //
        // answer = 5 * 6;
        // Debug.Log(answer);
        //
        // answer = 8 / 4;
        // Debug.Log(answer);

        // int n1 = 8;
        // int n2 = 9;
        // int answer;
        // answer = n1 + n2;
        // Debug.Log(answer);

        // int answer = 10;
        // answer += 5;
        // Debug.Log(answer);

        // int answer = 10;
        // answer++;
        // Debug.Log(answer);

        // string str1 = "happy ";
        // string str2 = "birthday";
        // string message;
        //
        // message = str1 + str2;
        // Debug.Log(message);
        
        // string str1 = "happy ";
        // string str2 = "birthday";
        //
        // str1 += str2;
        // Debug.Log(str1);

        // string str = "happy ";
        // int num = 123;
        //
        // string messagee = str + num;
        // Debug.Log(messagee);

        // int herbNum = 1;
        // if (herbNum == 1)
        // {
        //     Debug.Log("체력을 50 회복");
        // }

        // int hp = 200;
        // // int hp = 0
        // if (hp >= 100)
        // {
        //     Debug.Log("공격!");
        // }
        // else
        // {
        //     Debug.Log("방어!");
        // }

        // int hp = 180;
        // if (hp <= 50)
        // {
        //     Debug.Log("도망!");
        // }
        // else if (hp >= 200)
        // {
        //     Debug.Log("공격!");
        // }
        // else
        // {
        //     Debug.Log("방어!");
        // }

        // int x = 1;
        // if (x == 1)
        // {
        //     int y = 2;
        //     Debug.Log(x);
        //     Debug.Log(y);
        // }
        // // Debug.Log(y);

        // for (int i = 0; i < 5; i++)
        // {
        //     Debug.Log(i);
        // }

        // for (int i = 0; i < 10; i += 2)
        // {
        //     Debug.Log(i);
        // }

        // for (int i = 3; i <= 5; i++)
        // {
        //     Debug.Log(i);
        // }
        
        // for (int i = 3; i >= 0; i--)
        // {
        //     Debug.Log(i);
        // }
        
        // int sum = 0;
        // for (int i = 1; i <= 10; i++)
        // {
        //     sum += i;
        // }
        // Debug.Log(sum);

        // 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]);
        // }
        
        // int[] points  = { 83, 99, 52, 93, 15 };
        //
        // for (int i = 0; i < points.Length; i++)
        // {
        //     if (points[i] >= 90)
        //     {
        //         Debug.Log(points[i]);
        //     }
        // }
        
        // int[] points  = { 83, 99, 52, 93, 15 };
        //
        // int sum = 0;
        // for (int i = 0; i < points.Length; i++)
        // {
        //     sum +=  points[i];
        // }
        //
        // int average = sum / points.Length;
        // Debug.Log(average);
        
        // SayHello();
        
        // CallName("Tom");

        // int answer;
        // answer = Add(2, 3);
        // Debug.Log(answer);

        // int answer;
        // int num1 = 2;
        // int num2 = 3;
        // answer = Add(num1, num2);
        // Debug.Log(answer);
        
        // Player myPlayer = new Player();
        // myPlayer.Attack();
        // myPlayer.Damage(30);
        
        // Vector2 playerPos = new Vector2(3.0f, 4.0f);
        // playerPos.x += 8.0f;
        // playerPos.y += 5.0f;
        // Debug.Log(playerPos);

        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);
    }

    // Update is called once per frame
    void Update()
    {
        // Debug.Log("Update");
    }
}