문제 1

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

public class Test01 : MonoBehaviour
{
    public TMP_InputField nameInputField;
    public Button button;

    void Start()
    {
        button.onClick.AddListener(OnSubmitClicked);
    }

    void OnSubmitClicked()
    {
        Debug.Log(nameInputField.text);
    }
}

 

+++

 

문제 2

 

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

public class Test02 : MonoBehaviour
{
    public GameObject switch_On;
    public GameObject switch_Off;

    public Button switch_btn;


    void Start()
    {

        switch_On.gameObject.SetActive(true);
        switch_Off.gameObject.SetActive(false);

        switch_btn.onClick.AddListener(() =>
        {
            if(switch_On.gameObject.activeSelf == true)
            {
                switch_On.gameObject.SetActive(false);
                switch_Off.gameObject.SetActive(true);
            }
            else
            {
                switch_On.gameObject.SetActive(true);
                switch_Off.gameObject.SetActive(false);
            }
        });

       

    }

  
}

 

 

 

+++

 

 

문제 3

 

 

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

public class Test03 : MonoBehaviour
{
    private Slider slider;

    public TMP_Text currentValueText;
    public TMP_Text maxValueText;

    void Start()
    {
        slider = GetComponent<Slider>();

        maxValueText.text = slider.maxValue.ToString();
        currentValueText.text = slider.value.ToString();
        slider.onValueChanged.AddListener(OnSliderValueChanged);
    }

    private void OnSliderValueChanged(float value)
    {
        currentValueText.text = value.ToString();

        Debug.Log(currentValueText.text);
    }
}

 

 

+++

 

문제 4

 

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using TMPro; // TextMeshPro를 사용하는 경우 필요

public class Test04 : MonoBehaviour
{
    private Button skillButton;
    public Image cooldownImage;
    public TMP_Text cooldownText; 

    private float cooldownDuration = 5f; 
    private float timeLeft; 

    void Start()
    {
        skillButton = GetComponent<Button>();
        skillButton.onClick.AddListener(ActivateSkill);
        cooldownImage.fillAmount = 0;
    }

    void Update()
    {
        if (timeLeft > 0)
        {
            timeLeft -= Time.deltaTime;
            cooldownImage.fillAmount = timeLeft / cooldownDuration;
            cooldownText.text = timeLeft.ToString("F0");
            skillButton.enabled = false;
        }
        else
        {
            cooldownText.text = "";
            skillButton.enabled = true;
        }
    }

    void ActivateSkill()
    {
        if (timeLeft <= 0)
        {
            timeLeft = cooldownDuration;

        }
    }
}

 

 

+++

 

 

문제 5

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; // UI 사용을 위해 추가

public class Test05 : MonoBehaviour
{
    private Vector3 targetPosition;

    public GameObject bossGauge;
    public Vector3 GaugeOffset;

    void Start()
    {
        targetPosition = transform.position;
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            targetPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane));
            targetPosition.z = transform.position.z;
        }

        transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime * 5);

        Vector3 screenPosition = Camera.main.WorldToScreenPoint(transform.position + GaugeOffset);

        bossGauge.GetComponent<RectTransform>().position = screenPosition;
    }
}

+ Recent posts