Test.class
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class Test : MonoBehaviour
{
public GameObject flagGo;
public float speed = 2;
RaycastHit hit = default;
private void Awake()
{
}
private void Update()
{
if (Input.GetMouseButtonDown(1))
{
Debug.LogFormat("down! {0}", Input.mousePosition); // x y z screen (pixel)
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(ray.origin, ray.direction * 1000f, Color.blue , 1f);
if (Physics.Raycast(ray, out hit, 1000)) {
Debug.LogFormat("hit: {0}", hit.point);
//this.flagGo.transform.position = hit.point;
}
}
var moveDir = Vector3.Normalize(hit.point - this.flagGo.transform.position);
var distance = Vector3.Distance(this.flagGo.transform.position, hit.point);
var displacement = moveDir * this.speed * Time.deltaTime;
if (distance >= 0.2f)
{
this.flagGo.transform.Translate(displacement);
}
}
}
|
'Unity > 수업내용' 카테고리의 다른 글
2020-05-25 HudTextTest (0) | 2020.05.25 |
---|---|
2020-05-22 수업내용 로그인 화면 만들기 (0) | 2020.05.22 |
2020-05-21 수업내용 캐릭터선택 및 상태화면 (0) | 2020.05.22 |
2020-05-19 수업내용 스크롤뷰 (0) | 2020.05.19 |
2020-05-18 유니티 UITitle 만들기 (0) | 2020.05.18 |