#13 Now summons boat prefab when user drop the card
This commit is contained in:
parent
9e27d0f29f
commit
5b457ae5be
@ -4284,6 +4284,7 @@ MonoBehaviour:
|
|||||||
_persistent: 0
|
_persistent: 0
|
||||||
mouseSpot: {fileID: 1347266192824951316, guid: 049de7a77e0534ced92b672937a0f8db,
|
mouseSpot: {fileID: 1347266192824951316, guid: 049de7a77e0534ced92b672937a0f8db,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
boat: {fileID: 2987405546353765599, guid: 96173da392e9a408d9aea814b4cfe00e, type: 3}
|
||||||
--- !u!4 &107190135
|
--- !u!4 &107190135
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -9332,6 +9333,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: d3be018f5bcd344d2abd41e15265e325, type: 3}
|
m_Script: {fileID: 11500000, guid: d3be018f5bcd344d2abd41e15265e325, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
maxDistance: 500
|
||||||
--- !u!114 &212218605
|
--- !u!114 &212218605
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -27911,6 +27913,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: d3be018f5bcd344d2abd41e15265e325, type: 3}
|
m_Script: {fileID: 11500000, guid: d3be018f5bcd344d2abd41e15265e325, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
maxDistance: 500
|
||||||
--- !u!114 &717949311
|
--- !u!114 &717949311
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -28476,6 +28479,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: d3be018f5bcd344d2abd41e15265e325, type: 3}
|
m_Script: {fileID: 11500000, guid: d3be018f5bcd344d2abd41e15265e325, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
maxDistance: 500
|
||||||
--- !u!222 &729135463
|
--- !u!222 &729135463
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -70792,7 +70796,7 @@ BoxCollider:
|
|||||||
m_ProvidesContacts: 0
|
m_ProvidesContacts: 0
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
m_Size: {x: 100, y: 4, z: 100}
|
m_Size: {x: 100, y: 0.1, z: 100}
|
||||||
m_Center: {x: 0, y: 0, z: 0}
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &1561538019
|
--- !u!1 &1561538019
|
||||||
GameObject:
|
GameObject:
|
||||||
@ -70947,6 +70951,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: d3be018f5bcd344d2abd41e15265e325, type: 3}
|
m_Script: {fileID: 11500000, guid: d3be018f5bcd344d2abd41e15265e325, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
maxDistance: 500
|
||||||
--- !u!114 &1561538023
|
--- !u!114 &1561538023
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -13,6 +13,8 @@ public class Boat : MonoBehaviour
|
|||||||
|
|
||||||
private Coroutine draw;
|
private Coroutine draw;
|
||||||
|
|
||||||
|
public Vector3 target { get; set; }
|
||||||
|
|
||||||
public delegate void LandedEventHandler();
|
public delegate void LandedEventHandler();
|
||||||
public event LandedEventHandler OnLanded;
|
public event LandedEventHandler OnLanded;
|
||||||
|
|
||||||
@ -28,33 +30,26 @@ public class Boat : MonoBehaviour
|
|||||||
spot = Instantiate(DataManager.Inst.mouseSpot);
|
spot = Instantiate(DataManager.Inst.mouseSpot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
agent.SetDestination(target);
|
||||||
|
|
||||||
|
spot.gameObject.SetActive(true);
|
||||||
|
spot.transform.position = target;
|
||||||
|
|
||||||
|
if (draw != null) StopCoroutine(draw);
|
||||||
|
draw = StartCoroutine(DrawPath());
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Input.GetMouseButtonDown(0))
|
if (!(agent.remainingDistance < 0.1f && !agent.pathPending)) return;
|
||||||
{
|
spot.gameObject.SetActive(false);
|
||||||
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
||||||
RaycastHit hit;
|
|
||||||
|
|
||||||
if (Physics.Raycast(ray, out hit, 1000f))
|
|
||||||
{
|
|
||||||
agent.SetDestination(hit.point);
|
|
||||||
|
|
||||||
spot.gameObject.SetActive(true);
|
|
||||||
spot.transform.position = hit.point;
|
|
||||||
|
|
||||||
if (draw != null) StopCoroutine(draw);
|
|
||||||
draw = StartCoroutine(DrawPath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (agent.remainingDistance < 0.1f)
|
|
||||||
{
|
|
||||||
spot.gameObject.SetActive(false);
|
|
||||||
|
|
||||||
lineRenderer.enabled = false;
|
lineRenderer.enabled = false;
|
||||||
if (draw != null) StopCoroutine(draw);
|
if (draw != null) StopCoroutine(draw);
|
||||||
|
|
||||||
OnLanded?.Invoke();
|
OnLanded?.Invoke();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator DrawPath()
|
private IEnumerator DrawPath()
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
@ -8,6 +10,11 @@ public class DraggableCard : MonoBehaviour, IPointerDownHandler, IDragHandler, I
|
|||||||
private Vector3 originalScale;
|
private Vector3 originalScale;
|
||||||
private CanvasGroup canvasGroup;
|
private CanvasGroup canvasGroup;
|
||||||
|
|
||||||
|
[InfoBox("카드가 작아지는 속도 입니다. 높을수록 천천히 작아집니다.")] [Range(0f, 1000f)]
|
||||||
|
public float maxDistance = 500f;
|
||||||
|
|
||||||
|
private Coroutine scaleDown;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
canvasGroup = GetComponent<CanvasGroup>();
|
canvasGroup = GetComponent<CanvasGroup>();
|
||||||
@ -19,7 +26,9 @@ public class DraggableCard : MonoBehaviour, IPointerDownHandler, IDragHandler, I
|
|||||||
originalPosition = transform1.position;
|
originalPosition = transform1.position;
|
||||||
originalScale = transform1.localScale;
|
originalScale = transform1.localScale;
|
||||||
canvasGroup.alpha = 0.5f;
|
canvasGroup.alpha = 0.5f;
|
||||||
transform1.localScale = new Vector3(0.3f, 0.3f, 1f);
|
//transform1.localScale = new Vector3(0.3f, 0.3f, 1f);
|
||||||
|
if (scaleDown != null) StopCoroutine(scaleDown);
|
||||||
|
scaleDown = StartCoroutine(ScaleDown());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDrag(PointerEventData eventData)
|
public void OnDrag(PointerEventData eventData)
|
||||||
@ -27,10 +36,9 @@ public class DraggableCard : MonoBehaviour, IPointerDownHandler, IDragHandler, I
|
|||||||
transform.position = Input.mousePosition;
|
transform.position = Input.mousePosition;
|
||||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||||
RaycastHit hit;
|
RaycastHit hit;
|
||||||
if (Physics.Raycast(ray, out hit) && hit.collider.CompareTag("Ground"))
|
if (Physics.Raycast(ray, out hit) && hit.collider.CompareTag("Ground"))
|
||||||
{
|
{
|
||||||
// 마우스가 Ground 위에 있을 때
|
// 마우스가 Ground 위에 있을 때
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +47,12 @@ public class DraggableCard : MonoBehaviour, IPointerDownHandler, IDragHandler, I
|
|||||||
// 지형에 올바르게 드롭되지 않으면
|
// 지형에 올바르게 드롭되지 않으면
|
||||||
if (!IsDroppedOnTarget())
|
if (!IsDroppedOnTarget())
|
||||||
{
|
{
|
||||||
|
if (scaleDown != null)
|
||||||
|
{
|
||||||
|
StopCoroutine(scaleDown);
|
||||||
|
scaleDown = null;
|
||||||
|
}
|
||||||
|
|
||||||
var transform1 = transform;
|
var transform1 = transform;
|
||||||
transform1.position = originalPosition;
|
transform1.position = originalPosition;
|
||||||
transform1.localScale = originalScale;
|
transform1.localScale = originalScale;
|
||||||
@ -49,16 +63,49 @@ public class DraggableCard : MonoBehaviour, IPointerDownHandler, IDragHandler, I
|
|||||||
private bool IsDroppedOnTarget()
|
private bool IsDroppedOnTarget()
|
||||||
{
|
{
|
||||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||||
RaycastHit hit;
|
RaycastHit hit;
|
||||||
|
|
||||||
if (Physics.Raycast(ray, out hit))
|
if (Physics.Raycast(ray, out hit))
|
||||||
|
{
|
||||||
|
print(hit.collider.tag);
|
||||||
|
if (hit.collider.CompareTag("Ground"))
|
||||||
{
|
{
|
||||||
if (hit.collider.CompareTag("Ground"))
|
Destroy(gameObject);
|
||||||
{
|
var obj = Instantiate(DataManager.Inst.boat, GameManager.Inst.player.transform.position,
|
||||||
Destroy(gameObject);
|
Quaternion.identity);
|
||||||
return true;
|
obj.GetComponent<Boat>().target = hit.point;
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private IEnumerator ScaleDown()
|
||||||
|
{
|
||||||
|
var originalScale = transform.localScale;
|
||||||
|
var targetScale = new Vector3(0.3f, 0.3f, 1f);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// 현재 위치와 원래 위치 사이의 거리를 계산
|
||||||
|
var distance = Vector3.Distance(originalPosition, transform.position);
|
||||||
|
|
||||||
|
// 비율을 계산 (0 = 같은 위치, 1 = maxDistance만큼나 이상 떨어져 있음)
|
||||||
|
var ratio = Mathf.Min(distance / maxDistance, 1f);
|
||||||
|
|
||||||
|
// SmoothStep 사용하면, 천천히 시작해서 점차 빠르게 변화합니다.
|
||||||
|
// float의 경우만 사용할 수 있으므로, Vector3의 모든 요소에 일일이 적용해야 합니다.
|
||||||
|
var newScale = new Vector3(
|
||||||
|
Mathf.SmoothStep(originalScale.x, targetScale.x, ratio),
|
||||||
|
Mathf.SmoothStep(originalScale.y, targetScale.y, ratio),
|
||||||
|
Mathf.SmoothStep(originalScale.z, targetScale.z, ratio)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 조정한 스케일을 적용
|
||||||
|
transform.localScale = newScale;
|
||||||
|
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,4 +5,5 @@ using UnityEngine;
|
|||||||
public class DataManager : Singleton<DataManager>
|
public class DataManager : Singleton<DataManager>
|
||||||
{
|
{
|
||||||
public GameObject mouseSpot;
|
public GameObject mouseSpot;
|
||||||
|
public GameObject boat;
|
||||||
}
|
}
|
@ -53,7 +53,7 @@ BoxCollider:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 0
|
m_Bits: 0
|
||||||
m_LayerOverridePriority: 0
|
m_LayerOverridePriority: 0
|
||||||
m_IsTrigger: 0
|
m_IsTrigger: 1
|
||||||
m_ProvidesContacts: 0
|
m_ProvidesContacts: 0
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
|
@ -18,7 +18,7 @@ PhysicsManager:
|
|||||||
m_ClothInterCollisionDistance: 0.1
|
m_ClothInterCollisionDistance: 0.1
|
||||||
m_ClothInterCollisionStiffness: 0.2
|
m_ClothInterCollisionStiffness: 0.2
|
||||||
m_ContactsGeneration: 1
|
m_ContactsGeneration: 1
|
||||||
m_LayerCollisionMatrix: 100000001000000010000000100f00001f080000000000000000000000000000080700000807000008070000181000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
m_LayerCollisionMatrix: 100000001000000010000000381f00001f080000080000000000000000000000080700000807000008070000181000000808000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
m_SimulationMode: 0
|
m_SimulationMode: 0
|
||||||
m_AutoSyncTransforms: 0
|
m_AutoSyncTransforms: 0
|
||||||
m_ReuseCollisionCallbacks: 0
|
m_ReuseCollisionCallbacks: 0
|
||||||
|
Loading…
Reference in New Issue
Block a user