22.01.17 [홈워크] 표창 던지기

2022. 1. 17. 18:38Unity3D/수업 과제

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

public class Throw : MonoBehaviour
{
    public float rotSpeed;
    public Vector2 thrSpeed;
    private Vector2 startPos;
    private Vector2 endPos;

    void Start()
    {
        
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            this.startPos = Input.mousePosition;
            this.gameObject.transform.position = new Vector2(0f, -4f);
            rotSpeed = 0f;
            thrSpeed = Vector2.zero;
            this.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, 0f));
        }
        if (Input.GetMouseButtonUp(0))
        {
            this.endPos = Input.mousePosition;
            Vector2 dir = endPos - startPos;
            
            if(dir.y > 0)
            {
                thrSpeed = new Vector2(dir.x, dir.y);
                rotSpeed = dir.magnitude;
            }
        }
        this.transform.Rotate(0f, 0f, rotSpeed / 8f);
        this.transform.Translate(new Vector2(thrSpeed.x, thrSpeed.y) * 0.22f * Time.deltaTime, Space.World);
    }
}

 

 

'Unity3D > 수업 과제' 카테고리의 다른 글

22.02.09 유저 인터페이스 완성하기  (0) 2022.02.09
22.01.26 논스톱 나이트 모작하기  (0) 2022.01.26
22.01.20 MiniTest  (0) 2022.01.20
22.01.19 Cat Escape Two  (0) 2022.01.19
22.01.18 Cat Escape 피하기 게임 만들기  (0) 2022.01.18