2023/01/04

์•ˆ์„ํ™˜ยท2024๋…„ 1์›” 4์ผ
0

์˜ค๋Š˜ ๋ฐฐ์šด ์ฝ”๋“œ


  1. Stack<>

๐Ÿ’พ ์ฝ”๋“œ

using System;
using System.Collections.Generic;

public class Solution {
    public int solution(int n) {
        
        Stack<int> ternary = Converter(n, 3);
        //n์„ 3์ง„๋ฒ•์œผ๋กœ ๋ณ€ํ™˜
        
        int answer = 0;
        int size = 1; // ์ž๋ฆฟ์ˆ˜ ๊ณ„์‚ฐ์šฉ ๋ณ€์ˆ˜ ์ถ”๊ฐ€

        while (ternary.Count > 0) {
            answer += ternary.Pop() * size;
            //์„ ์ž… ํ›„์ถœ ๊ตฌ์กฐ๋กœ์„œ ๋งˆ์ง€๋ง‰๋ถ€ํ„ฐ ๊ณ„์‚ฐ(์ž๋ฆฟ์ˆ˜๋ฅผ ๋’ค์ง‘์„ ํ•„์š”๊ฐ€ ์—†์Œ)
            size *= 3;
            //3์ง„๋ฒ• ๊ตฌ์กฐ
        }
        
        return answer;
    }
    
    public Stack<int> Converter(int num, int size) {
        Stack<int> ternary = new Stack<int>();
        //์ž„์‹œ ์Šคํƒ ์ €์žฅ์†Œ ์ƒ์„ฑ
        
        while(num > 0) {
            int temp = num % size;
            ternary.Push(temp);
            //3์ง„๋ฒ•์„ ์Šคํƒํ˜•์‹์œผ๋กœ ์Œ“์Œ
            num /= size;
        }
        //3์ง„๋ฒ•์œผ๋กœ ๋ณ€ํ™˜
        
        return ternary;
    }
}


  1. OverlapCircleAll(Position, scanRadius)
  • position์„ ๊ธฐ์ค€ ์›ํ˜•์œผ๋กœ ScanRadius ๋ฒ”์œ„๋งŒํผ์˜ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ธ์‹ํ•œ๋‹ค

๐Ÿ’พ ์ฝ”๋“œ

using UnityEngine;

public class ObjectScanner : MonoBehaviour
{
    public Transform playerTransform; // ํ”Œ๋ ˆ์ด์–ด์˜ Transform์„ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    public float scanRadius = 5f; // ๊ฒ€์ƒ‰ํ•  ๋ฐ˜๊ฒฝ

    void Update()
    {
        // ํ”Œ๋ ˆ์ด์–ด ์ฃผ๋ณ€์˜ ๋ชจ๋“  Collider2D๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
        Collider2D[] colliders = Physics2D.OverlapCircleAll(playerTransform.position, scanRadius);

        // ๊ฐ Collider2D์— ๋Œ€ํ•ด ์ฒ˜๋ฆฌ
        foreach (Collider2D collider in colliders)
        {
            // ์—ฌ๊ธฐ์—์„œ ์›ํ•˜๋Š” ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
            // ์˜ˆ๋ฅผ ๋“ค์–ด, ํ•ด๋‹น ๊ฐ์ฒด์˜ ํƒœ๊ทธ๋‚˜ ๋ ˆ์ด์–ด ๋“ฑ์„ ํ™•์ธํ•˜์—ฌ ์›ํ•˜๋Š” ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
            if (collider.CompareTag("InteractiveObject"))
            {
                // ์ƒํ˜ธ์ž‘์šฉ ๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ
            }
        }
    }
}

๐Ÿ“– ์ฐธ๊ณ 

์ฐธ๊ณ ํ•  ์ฝ”๋“œ ๋‚ด์šฉ




๐Ÿง๊ธฐ๋ณธ ๊ณต๋ถ€ ๋‚ด์šฉ


  1. ๊ณต๋ถ€๋‚ด์šฉ x
  • ์„ค๋ช… x




โ›”๏ธ ์—๋Ÿฌ


  1. ๊นƒํ—ˆ๋ธŒ ์‚ฌ์šฉ ์Šคํฌ๋ฆฝํŠธ ์ด๋ฆ„ ์ค‘๋ณต
  • ์„œ๋กœ ํ•ฉ์˜ํ•˜์— ์Šคํฌ๋ฆฝํŠธ ์ด๋ฆ„ ์ˆ˜์ •


  1. ๊นƒํ—ˆ๋ธŒ ์‚ฌ์šฉ ์Šคํฌ๋ฆฝํŠธ ์ด๋ฆ„ ์ค‘๋ณต
  • ์„œ๋กœ ํ•ฉ์˜ํ•˜์— ์Šคํฌ๋ฆฝํŠธ ์ด๋ฆ„ ์ˆ˜์ •




๐Ÿ’ญ ๋Š๋‚€์ 


  1. ์ฑ…์ข€ ์ฝ์–ด์•ผ๊ฒ ๋‹ค
  • ๋…ธ์…˜์— ์ฑ… ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜๊ณ  ์Œ“์•„๊ฐ€์ž
profile
์•ˆ์„ํ™˜!

0๊ฐœ์˜ ๋Œ“๊ธ€