StarController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StarController : MonoBehaviour
{
private float speed = 0;
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;
}
else if (Input.GetMouseButtonUp(0))
{
Vector2 endPos = Input.mousePosition;
float len = endPos.y - startPos.y;
this.speed = len / 800.0f;
}
this.transform.Translate(0, speed, 0, Space.World);
if (speed > 0)
{
this.transform.Rotate(0, 0, 10.0f);
}
speed *= 0.98f;
}
}
GameDirectorStar
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameDirectorStar : MonoBehaviour
{
GameObject shuriken;
GameObject ground;
GameObject distance;
// Start is called before the first frame update
void Start()
{
this.shuriken = GameObject.Find("shuriken");
this.ground = GameObject.Find("ground");
this.distance = GameObject.Find("Direction");
}
// Update is called once per frame
void Update()
{
var ay = shuriken.transform.position.y;
var by = ground.transform.position.y;
var len = by - ay;
Text textDirection = distance.GetComponent<Text>();
if (len >= 0)
{
textDirection.text = string.Format("목표 거리 {0:F2}", len);
}
else
{
textDirection.text = string.Format("Gameover");
}
}
}
'Unity > 수업내용' 카테고리의 다른 글
[Unity 3D / 유니티 교과서] 7장 예제 Bamsongi (0) | 2023.02.01 |
---|---|
[Unity 2D / 유니티 교과서] 6장 예제 ClimbCloud (0) | 2023.02.01 |
[Unity 2D / 유니티 교과서] 5장 예제 (0) | 2023.01.31 |
[Unity 2D / 유니티 교과서] 4장 예제 SwipeCar (0) | 2023.01.30 |
[Unity 2D / 유니티교과서] 3장 예제 Roulette (0) | 2023.01.30 |