78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SkinScript : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
MeshFilter meshFilter;
|
|
public Mesh mesh1;
|
|
public Mesh mesh2;
|
|
public Mesh mesh3;
|
|
public Mesh mesh4;
|
|
public Mesh mesh5;
|
|
public Mesh mesh6;
|
|
public Mesh mesh7;
|
|
|
|
int counter = 0;
|
|
void Start()
|
|
{
|
|
meshFilter = GetComponent<MeshFilter>();
|
|
meshFilter.mesh = mesh1;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.name=="Needle" ) // Make sure to set an appropriate tag for your cube
|
|
{
|
|
|
|
//Debug.Log("Needle entered the cube.");
|
|
//find the coordonates of the entering point
|
|
var entrypoint =this.GetComponent<MeshCollider>().ClosestPointOnBounds(transform.position);
|
|
Debug.Log("Point: " + entrypoint);
|
|
//save all entering points in a vector
|
|
|
|
// Perform actions when the needle enters the cube
|
|
// Example: Record entry point or start a suture action
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (other.gameObject.name=="Needle") // Make sure to set an appropriate tag for your cube
|
|
{
|
|
counter++;
|
|
if (counter == 2)
|
|
{
|
|
meshFilter.mesh = mesh2;
|
|
}
|
|
if (counter == 4)
|
|
{
|
|
meshFilter.mesh = mesh3;
|
|
}
|
|
if (counter == 6)
|
|
{
|
|
meshFilter.mesh = mesh4;
|
|
}
|
|
if (counter == 8)
|
|
{
|
|
meshFilter.mesh = mesh5;
|
|
}
|
|
if (counter == 10)
|
|
{
|
|
meshFilter.mesh = mesh6;
|
|
}
|
|
if (counter == 12)
|
|
{
|
|
meshFilter.mesh = mesh7;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|