그림에서

name

min_damage

max_damage

item_type

4가지 속성을 가지고 배열을 만들어서 json 파일로저장

 

json파일을 만들때 " "가 중요하다.

 

만들고 나서 Format을 누르면 잘 작성이 됬는지 확인할 수 있다

코드를 작성 후 오류가 나지 않으면 이렇게 생성 된 걸 알 수 있다.

 

그 후 Text를 복사하고 메모장에 저장

저장할 때 주의

 

우선 Unity에 Resources 라는 폴더를 만들고 넣어주면 되는데 이 때 반드시 폴더명을 이렇게 해주어야 한다.

https://www.newtonsoft.com/json

 

Json.NET - Newtonsoft

× PM> Install-Package Newtonsoft.Json or Install via VS Package Management window. ZIP file containing Json.NET assemblies and source code: Json.NET

www.newtonsoft.com

Newtonsoft.Json은 C#에서 JSON 데이터를 처리하는 데 사용되는 강력한 라이브러. 주요 기능은 다음과 같다.

  1. JSON 직렬화(Serialization): C# 객체를 JSON 문자열로 변환합니다.
  2. JSON 역직렬화(Deserialization): JSON 문자열을 C# 객체로 변환합니다.
  3. LINQ를 사용한 JSON 쿼리(Query): LINQ 쿼리를 사용하여 JSON 데이터를 쉽게 쿼리하고 필터링할 수 있습니다.
  4. JSON 스키마(Validation): JSON 데이터가 주어진 스키마에 부합하는지 확인할 수 있습니다.
  5. JSON 파싱(Parsing): JSON 문자열을 해석하고 객체로 변환합니다.
  6. JSON 변환(Transform): JSON 데이터를 다른 형식으로 변환합니다.
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class HelmMain : MonoBehaviour
{
    
    void Start()
    {
        TextAsset asset = Resources.Load<TextAsset>("helm_data");
        string json = asset.text;
        Debug.Log(json);

        HelmData data = JsonConvert.DeserializeObject<HelmData>(json);
        //Debug.Log(data);  
        Debug.LogFormat("{0} {1} {2} {3}", data.name, data.min_damage, data.max_damage, data.item_type);

        //저장
        //직렬화 객체 생성
        HelmInfo info = new HelmInfo(data.min_damage, data.max_damage);
        //직렬화 시작(객체 ->문자열)
        string serializedJson = JsonConvert.SerializeObject(info);

        //파일로 저장
        //Application.persistentDataPath : 플랫폼 OS에 따라 경로를 자동으로 잡아줌
        string path = Application.persistentDataPath + "/helm_info.json";
        Debug.Log(path);
        //문자열을 파일로 저장
        File.WriteAllText(path, serializedJson); //경로, 문자열
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HelmData
{
    public string name;
    public int min_damage;
    public int max_damage;
    public string item_type;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HelmInfo
{
    public int min_damage;
    public int max_damage;

    public HelmInfo(int min_damage, int max_damage)
    {
        this.min_damage = min_damage;
        this.max_damage = max_damage;
    }
}

실행을 시켜보면

1. 데이터를 문자열을 출력

2. 데이터를 역직렬화 후 데이터를 잘 받고 있는지 확인

3. Helminfo클래스를 메인에서 불러온 후 생성자를 생성한뒤 지정한 경로 위치로 생성후 저장 => 그 위치 출력

 

보기와 같이 출력한 경로를 검색하면 지정된 경로에 파일이 저장됨을 확인 할 수 있다.

기존에 있는 에셋을 다운받아

가이드라인으로 잡고 명암을 줄이고

그 에셋을 찾아 UI를 본뜨는 작업을 하였는데

그것을 하기 전에 제일 기초이자 중요한 GameObject.onClick.AddListener()를 다루려 한다.

 

Button1을 클릭하면 콘솔에 찍힌다.

 

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

public class Main : MonoBehaviour
{
    [SerializeField] private Button btn;

    void Start()
    {
        btn.onClick.AddListener(() =>
        {
            Debug.Log("button clicked!");
        });
    }
};

 

Button1을 클릭하면 2, 3번이 사라진다.

 

 

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

public class Main : MonoBehaviour
{
    [SerializeField] private Button btn1;

    [SerializeField] private Button btn2;
    [SerializeField] private Button btn3;

    void Start()
    {
        btn1.onClick.AddListener(() => {
            this.btn2.gameObject.SetActive(false);
            this.btn3.gameObject.SetActive(false);
        });
    }
}

 

Button1을 클릭하면 2, 3이 사라지는데

Button2, Butto3을 배열(btns)로 만들어서 할당하였다.

 

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

public class Main : MonoBehaviour
{
    [SerializeField] private Button btn1;

    [SerializeField] private Button[] btns;

    void Start()
    {
        btn1.onClick.AddListener(() => {

            for (int i = 0; i < this.btns.Length; i++)
            {
                Button btn = btns[i];
                btn.gameObject.SetActive(false);
            }
        });
    }
}

 

Button1, Button2를 btns(배열)에 할당하였고

Button3을 누를시 배열이 사라지고 Button4를 누를시 배열이 다시 생기게 작성

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

public class Main : MonoBehaviour
{
    [SerializeField] private Button btn3;
    [SerializeField] private Button btn4;
    [SerializeField] private Button[] btns; //btn1, btn2

    void Start()
    {
        btn3.onClick.AddListener(() =>
        {
            Debug.Log("버튼3 눌렸습니다.");
            for (int i = 0; i < this.btns.Length; i++)
            {
                Button btn = btns[i];
                btn.gameObject.SetActive(false);
            }
        });

        btn4.onClick.AddListener(() =>
        {
            Debug.Log("버튼4 눌렸습니다.");
            for (int i = 0; i < this.btns.Length; i++)
            {
                Button btn = btns[i];
                btn.gameObject.SetActive(true);
            }
        });
    }
}

'산대특 > 게임 알고리즘' 카테고리의 다른 글

AppleCatch  (0) 2024.02.06
동기와 비동기  (1) 2024.02.05
직렬화와 역직렬화  (0) 2024.02.05
디자인 패턴과 싱글톤 패턴  (0) 2024.02.05
Process 와 Thread 그리고 Thread 와 Coroutine  (1) 2024.02.04

1. ground 요소를 추가하여  Rigidbody 2D -> Body Type - Kinematic 설정하여

땅을 만들어 공중에 떠있게 만들어 주었다.

2. 캔버스 레거시 text로 velocityText를 만들어서 고양이가 제자리부터 이동거리를 수치로 표시

    -  ClimbCloudGameDirector 스크립트를 추가하고 CatController에 연결해줌으로 써 이동거리 표시

3. 고양이 선택후 Tool bar에서 Window - Animation- Animation에 들어가서 Create를 누른후 

     Assets안에 애니메이션 폴더를 만들어주고 걷는 애니메이션을 넣을 것으므로 이름을 Walk로 생성

     Animation탭 안에서 add property를 누르고 sprite 선택 후 적적할게 고양이가 나눠져서 걷는 그림을 넣어주었다.

    마지막으로 애니메이션 탭 안 우측 상단에 있는 add keyframe을 누른 후 적당한 거리 뒤에 넣으면

    마지막 프레임이 복사되고 그 프레임 안까지의 사진들이 연속적으로 실행된다.

    애니메이터는 CatController와 같은 위치에 있으므로 따로 호출하지 않아도 클래스 안에서 사용가능

    애니메이션속도를 캐릭터 움직임 속도에 맞춰 변하도록 설정

    this.anim.speed = (Mathf.Abs(this.rbody.velocity.x) / 2f);

 

4. 물리엔진을 사용해서 충돌판정

1. 둘중 하나는 리지드바디 컴포넌트가 있어야 한다

2. 두 객체모두 콜라이더가 있어야 한다

3. isTrigger 모드를 체크 한다

 

 

트리거모드는 업데이트보다 먼저 일어난다

 

5. 깃발에 도달(충돌)했을 때 화면 전환

6. 그후 화면을 터치하면 다시 복귀

7. 고양이 이동가능 거리 조절

8. 고양이가 공중에서 계속 점프하지 못하게 조건문 추가

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Assertions.Comparers;
using UnityEngine.SceneManagement;

public class CatController : MonoBehaviour
{
    [SerializeField] private Rigidbody2D rbody;
    [SerializeField] private float moveForce = 100f;
    [SerializeField] private float jumpForce = 680f;

    [SerializeField]
    private ClimbCloudGameDirector gameDirector;

    private Animator anim;

    private bool hasSpace = false;

    private void Start()
    {
        //this.gameObject.GetComponent<Animation>();

        anim = GetComponent<Animator>();

        //this.gameDirector = GameObject.Find("GameDirector").GetComponent<ClimbCloudGameDirector>();
        //this.gameDirector = GameObject.FindAnyObjectByType<ClimbCloudGameDirector>();

    }

    void Update()
    {
        //스페이스바를 누르면 
        if (Mathf.Abs(rbody.velocity.y) < 0.01f)

        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (!hasSpace)
                {
                    //힘을 가한다 
                    this.rbody.AddForce(this.transform.up * this.jumpForce);
                    //this.rbody.AddForce(Vector3.up * this.force);

                        hasSpace = false; // 다시 점프할 수 있도록 허용

                }
            }


        }
        // -1, 0, 1 : 방향 
        int dirX = 0;
        //왼쪽화살표키를 누르고 있는 동안에 
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            dirX = -1;
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            dirX = 1;
        }

        // Debug.Log(dirX); //방향 -1, 0, 1

        //스케일 X를 변경 하는데 키가 눌렸을 때만 
        //키가 눌렸을때만 = (dirX != 0)
        if (dirX != 0)
        {
            this.transform.localScale = new Vector3(dirX, 1, 1);
        }


        //벡터의 곱 
        //Debug.Log(this.transform.right * dirX);  //벡터3

        //도전 ! : 속도를 제한하자 
        //velocity.x 가 3정도가 넘어가니깐 빨라지는거 같드라구...
        if (Mathf.Abs(this.rbody.velocity.x) < 3)
        {
            this.rbody.AddForce(this.transform.right * dirX * moveForce);
        }

        this.anim.speed = (Mathf.Abs(this.rbody.velocity.x) / 2f);
        this.gameDirector.UpdateVelocityText(this.rbody.velocity);


        // Debug.Log(this.transform.position);

        float clampX = Mathf.Clamp(this.transform.position.x, -2.39f, 2.35f);
        Vector3 pos = this.transform.position;
        pos.x = clampX;
        this.transform.position = pos;


    }

    // Trigger 모드 일경우 충돌 판정을 해주는 이벤트 함수
    private bool hasEntered = false;
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!hasEntered)
        {
            Debug.LogFormat("OnTriggerEnter2D: {0}", collision);
            SceneManager.LoadScene("ClimbCloudClear");
            hasEntered = true; // 한 번 이벤트가 발생하면 이 변수를 true로 설정하여 두 번 이상 호출되지 않도록 함

        }

    }



}

 

using System.Collections;
using System.Collections.Generic;
using UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ChangeScene : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            
            SceneManager.LoadScene("ClimbCloud");
            Debug.Log("화면이 전환됨");
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ClimbCloudGameDirector : MonoBehaviour
{
    [SerializeField] private Text velocityText;

    public void UpdateVelocityText(Vector2 velocity)
    {
        float velocityX = Mathf.Abs(velocity.x);
        this.velocityText.text = velocityX.ToString();
    }
}


+ 개선할 점

 

카메라가 고양이 따라가기

'산대특 > 게임 알고리즘' 카테고리의 다른 글

Pirate Bomb - Captain(Enemy)  (0) 2024.02.02
Pirate Bomb - BombGuy  (0) 2024.02.02
ClimbCloud  (2) 2024.02.01
C# 대리자, 람다함수  (1) 2024.01.31
Git, SourceTree  (1) 2024.01.31
R&D
1. 고양이(Player)가 구름 위에서 점프할 수 있도록 구현
2. 고양이가 좌우로 이동할 수 있도록 구현

 

텍스쳐와 하이어라이키를 추가하였고

 

이번에 중요한 점은 Rigidbody 2D 와 Collider 2D이다.

 

콜라이더란 물리 충돌 처리를 위한 오브젝트

고양이와 구름 둘 다 리지드바디와 콜라이더 오브젝트를 추가

그리고 각각의 radius(반지름), offset을 이용하여 크기를 조정

리지드바디

Rigidbody  GameObject 가 물리 제어로 동작하게 합니다.

리지드바디는 힘과 토크를 받아 오브젝트가 사실적으로 움직이도록 해줍니다.

리지드바디가 포함된 모든 게임 오브젝트는 중력의 영향을 받아야 하며 스크립팅을 통해 가해진 힘으로 움직이거나 NVIDIA PhysX 물리 엔진을 통해 다른 오브젝트와 상호 작용해야 합니다.

https://docs.unity3d.com/kr/2021.3/Manual/class-Rigidbody.html

 

리지드바디 - Unity 매뉴얼

Rigidbody 는 GameObject 가 물리 제어로 동작하게 합니다. 리지드바디는 힘과 토크를 받아 오브젝트가 사실적으로 움직이도록 해줍니다. 리지드바디가 포함된 모든 게임 오브젝트는 중력의 영향을

docs.unity3d.com

 

콜라이더

콜라이더(Collider) 컴포넌트는 물리 충돌 처리를 위한 오브젝트의 형태를 정의합니다. 콜라이더는 보이지 않는 요소이므로 오브젝트의 메시와 정확히 동일한 모양일 필요는 없으며, 실제로는 게임플레이 시에는 대략적인 근사치로도 크게 구분되지 않으며 더 효율적입니다.

가장 간단한(그리고 프로세서에 부하를 주지 않는) 콜라이더는 기본 콜라이더 타입입니다. 3D에서는 박스 콜라이더, 스피어 콜라이더, 캡슐 콜라이더가 바로 이 타입입니다. 2D에서는 박스 콜라이더 2D 써클 콜라이더 2D를 사용할 수 있습니다. 복합 콜라이더 를 만들기 위해 하나의 오브젝트에 위와 같은 콜라이더를 몇 개든 추가할 수 있습니다.

https://docs.unity3d.com/kr/2018.4/Manual/CollidersOverview.html

 

콜라이더 - Unity 매뉴얼

콜라이더(Collider) 컴포넌트는 물리 충돌 처리를 위한 오브젝트의 형태를 정의합니다. 콜라이더는 보이지 않는 요소이므로 오브젝트의 메시와 정확히 동일한 모양일 필요는 없으며, 실제로는 게

docs.unity3d.com

 

구름도 중력의 영향을 받아 떨어지는 것을 방지하기 위해 kinematic사용

Rigidbody 2D -> Body type -> Kinematic

 

회전축인 z축을 고정하지 않으면 다음과 같이 구름에 닿으면 넘어진다.

 

 

Constraints - Freeze Rotation - z축(초록색 회전축)의  Rotation 값을 고정

회전축인 z축을 고정하면 다음과 같이 구름에 닿으면 고정된다.

 

스페이스를 누르면 고양이가 점프를 하고

마지막으로 방향키로 고양이를 이동할 수 있도록 구현하였다.

Rigidbody.AddForce(transform.up * force)

AddForce 안에는 방향 * 힘이 들어오면 된다.

 

이동을하려면

this.rbody.AddForce(transform.right * dir * moveForce);

여기에서 방향 * 힘

 

using System.Collections;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;
using UnityEngine;

public class CatController : MonoBehaviour
{
    [SerializeField]
    private Rigidbody2D rbody;
    [SerializeField]
    private float jumpForce = 200f;
    [SerializeField]
    private float moveForce = 100f;
    
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("스페이스누름");
            rbody.AddForce(transform.up * jumpForce);
        }
        //방향 : -1, 0, 1
        int dir = 0;
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            dir = -1;
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            dir = 1;
        }
        //Debug.LogFormat(dir);
        //Debug.Log(this.transform.right * dir);

        this.rbody.AddForce(transform.right * dir * moveForce);

    }
}

'산대특 > 게임 알고리즘' 카테고리의 다른 글

Pirate Bomb - BombGuy  (0) 2024.02.02
ClimbCloud-2  (1) 2024.02.01
C# 대리자, 람다함수  (1) 2024.01.31
Git, SourceTree  (1) 2024.01.31
CatEscape 게임  (2) 2024.01.30

<예시 이미지>

이미지 예시

 

1. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Hand Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 3.2f;
            int minDamage = 2;
            int maxDamage = 3;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

 

 

1. 출력

 

2. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Aidan's Revenge";
            string weaponType = "Axe";
            float DamagePerSecond = 10.4f;
            int minDamage = 6;
            int maxDamage = 10;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

2. 출력

 

3. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Weathered Hand Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 3.0f;
            int minDamage = 2;
            int maxDamage = 3;
            float AttacksPerSecond = 1.20f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

3. 출력

 

4. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Broad Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 7.1f;
            int minDamage = 4;
            int maxDamage = 7;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

4.  출력

 

5. 코드

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Heavy Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 17.5f;
            int minDamage = 10;
            int maxDamage = 17;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

5. 출력

 

6. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Marauder Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 26.6f;
            int minDamage = 15;
            int maxDamage = 26;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

6. 출력

 

7. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Toporok";
            string weaponType = "Axe";
            float DamagePerSecond = 101.4f;
            int minDamage = 55;
            int maxDamage = 101;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

7. 출력

 

8. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Masakari";
            string weaponType = "Axe";
            float DamagePerSecond = 118.3f;
            int minDamage = 64;
            int maxDamage = 118;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

8. 출력

 

9. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Tomahawk";
            string weaponType = "Axe";
            float DamagePerSecond = 129.3f;
            int minDamage = 70;
            int maxDamage = 129 ;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

9. 출력

 

10. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Two-Handed Club";
            string weaponType = "Two-Handed Mace";
            float DamagePerSecond = 15.8f;
            int minDamage = 17;
            int maxDamage = 18 ;
            float AttacksPerSecond = 0.90f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

10. 출력

'산대특 > 게임 알고리즘' 카테고리의 다른 글

C# 대리자, 람다함수  (1) 2024.01.31
Git, SourceTree  (1) 2024.01.31
CatEscape 게임  (2) 2024.01.30
멤버 변수와 지역 변수  (0) 2024.01.29
유니티 실행 시 인터페이스  (0) 2024.01.25

+ Recent posts