https://assetstore.unity.com/packages/3d/props/weapons/katana-sword-free-143768
Katana Sword Free | 3D 무기 | Unity Asset Store
Elevate your workflow with the Katana Sword Free asset from Imagine Emotion. Find this & other 무기 options on the Unity Asset Store.
assetstore.unity.com
https://github.com/DavidArayan/ezy-slice
GitHub - DavidArayan/ezy-slice: An open source mesh slicer framework for Unity3D Game Engine. Written in C#.
An open source mesh slicer framework for Unity3D Game Engine. Written in C#. - DavidArayan/ezy-slice
github.com
using UnityEngine;
public class HalfExtentsVisualizer : MonoBehaviour
{
public Vector3 halfExtents = new Vector3(1, 1, 1);
public Color boxColor = Color.blue; // 상자의 색깔을 설정합니다.
public bool useWireframe = false; // 상자를 와이어프레임으로 그릴지 여부를 결정합니다.
void OnDrawGizmos()
{
// Gizmo 색상을 설정합니다.
Gizmos.color = boxColor;
// 오브젝트의 Collider로부터 중심 위치를 얻습니다.
Collider collider = GetComponent<Collider>();
Vector3 center = collider != null ? collider.bounds.center : transform.position;
// Gizmo의 변환 행렬을 설정합니다. 오브젝트의 회전은 반영하지만, 스케일은 1로 고정합니다.
Gizmos.matrix = Matrix4x4.TRS(center, transform.rotation, Vector3.one);
// 상자를 그립니다. useWireframe 값에 따라 와이어프레임 또는 솔리드 상자를 그립니다.
if (useWireframe)
{
Gizmos.DrawWireCube(Vector3.zero, 2.0f * halfExtents); // 와이어프레임 상자를 그립니다.
}
else
{
Gizmos.DrawCube(Vector3.zero, 2.0f * halfExtents); // 솔리드 상자를 그립니다.
}
}
}
using System.Collections;
using System.Collections.Generic;
using EzySlice;
using UnityEngine;
public class Slicer : MonoBehaviour
{
public Material afterSliceMaterial;
public LayerMask sliceMask;
public bool isTouch = false;
private void Update()
{
if (isTouch) {
Slice();
}
//if (Input.GetKeyDown(KeyCode.Space))
//{
// Slice();
//}
}
public void Slice()
{
Collider[] objectsToSlice = Physics.OverlapBox(transform.position, new Vector3(2.08f, 0.45f, 1.33f),
transform.rotation, sliceMask);
Debug.LogFormat("objectsToSlice.Length: {0}", objectsToSlice.Length);
foreach (Collider col in objectsToSlice)
{
SlicedHull slicedObject = SliceObject(col.gameObject);
Debug.LogFormat("slicedObject: {0}", slicedObject);
var upperHullGo = slicedObject.CreateUpperHull(col.gameObject, afterSliceMaterial);
var lowerHullGo = slicedObject.CreateLowerHull(col.gameObject, afterSliceMaterial);
Debug.LogFormat("upperHullGo: {0}", upperHullGo);
Debug.LogFormat("lowerHullGo: {0}", lowerHullGo);
upperHullGo.transform.position = col.transform.position;
lowerHullGo.transform.position = col.transform.position;
var velocity = col.GetComponent<Rigidbody>().velocity;
ApplyPhysical(upperHullGo, velocity);
ApplyPhysical(lowerHullGo, velocity);
Destroy(col.gameObject);
}
}
private void ApplyPhysical(GameObject go, Vector3 velocity)
{
go.AddComponent<MeshCollider>().convex = true;
var rbody = go.AddComponent<Rigidbody>();
rbody.velocity = -velocity;
int randX = UnityEngine.Random.Range(0, 3);
int randY = UnityEngine.Random.Range(0, 3);
int randZ = UnityEngine.Random.Range(0, 3);
rbody.AddForce(1.5f * new Vector3(randX, randY, randZ), ForceMode.Impulse);
}
private SlicedHull SliceObject(GameObject go)
{
return go.Slice(transform.position, transform.up, afterSliceMaterial);
}
}
위에 두개는 테스트 씬에서 플레인과 큐브를 만들고 되는지 확인 후 프리팹으로 뽑아와서 부착하였다.