실행 결과

GameDirector2.cs

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

public class GameDirector2 : MonoBehaviour
{
    public GameObject shuriken;
    [SerializeField]
    private GameObject ground;
    [SerializeField]
    private GameObject dt;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float len = this.ground.transform.position.y - this.shuriken.transform.position.y;
        Text textDt = this.dt.GetComponent<Text>();
        textDt.text = string.Format("{0}m", len.ToString("F2"));
        if (len < 0)
        {
            textDt.text = "성공";
        }
    }
}

ShuridenController.cs

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

public class ShurikenController : MonoBehaviour
{
    [SerializeField]
    private float speed;
    [SerializeField]
    private float rotSpeed = 0;
    [SerializeField]
    private Vector2 startPos;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // 마우스가 클릭한 곳의 좌표를 얻어옴
            this.startPos = Input.mousePosition;
            this.speed = 0.1f;
            this.rotSpeed = 15;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            Vector2 endPos = Input.mousePosition;
            var length = endPos.y - this.startPos.y;

            // 감속
            this.speed = length / 500f;
        }

        this.transform.Rotate(0, 0, this.rotSpeed);
        this.transform.position += new Vector3(0, this.speed, 0);
        this.rotSpeed *= 0.96f;

    }
}

shuriken Component
GameDirector Component

+ Recent posts