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;
}
}
'C# > 수업 내용' 카테고리의 다른 글
[Unity Shader] 유니티 쉐이더 기초 연습 (0) | 2022.08.08 |
---|---|
[C#] 알고리즘 문제 (0) | 2022.07.06 |
Json 연습 2 - 캐릭터, 경험치 데이터 (1) | 2022.06.21 |
Json 연습 - 같은 아이템의 개수(amount) 증가 (0) | 2022.06.20 |
대리자 연습 (0) | 2022.06.16 |