csharp
닫기using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasketController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//마우스 위치 확인
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(ray.origin, ray.direction * 100f, Color.red, 2f);
RaycastHit hit;
//Raycast와 충돌시 .. true
if (Physics.Raycast(ray, out hit, 100f))
{
//찍은 위치
Debug.LogFormat("hit.point: {0}", hit.point);
//바스켓 위치 마우스로 변경
//this.transform.position = hit.point;
//반올림
float x = Mathf.RoundToInt(hit.point.x);
float z = Mathf.RoundToInt(hit.point.z);
this.transform.position = new Vector3(x, 0, z);
}
}
}
}

'유니티 기초 > 복습' 카테고리의 다른 글
[주말과제] SimpleRPG 합치기 (1) | 2023.08.14 |
---|---|
SimpleRPG 복습 (0) | 2023.08.08 |
챕터6 ClimbCloud [미완] - 복습 (0) | 2023.08.04 |
챕터 5 고양이 탈출 복습 - [완] (0) | 2023.08.04 |
챕터5 고양이탈출 - CatEscape - 복습 (0) | 2023.08.02 |