(01-05-2019, 09:50 AM)josemendez Wrote: This is a regular C# event. Please read on how to use them.
https://www.tutorialspoint.com/csharp/csharp_events.htm
https://www.tutorialsteacher.com/csharp/csharp-event
I used code like this
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiTearableCloth))]
public class ClothTornEvent : MonoBehaviour
{
void Start()
{
this.GetComponent<ClothTornEvent>().enabled = false;
}
ObiTearableCloth cloth;
public GameObject thingToSpawn;
void OnEnable()
{
cloth = GetComponent<ObiTearableCloth>();
cloth.OnConstraintTorn += Cloth_OnConstraintTorn;
}
void OnDisable()
{
cloth.OnConstraintTorn -= Cloth_OnConstraintTorn;
}
void Cloth_OnConstraintTorn(object sender, ObiTearableCloth.ObiConstraintTornEventArgs e)
{
Debug.Log("1");
if (thingToSpawn != null)
{
GameObject.Instantiate(thingToSpawn, cloth.Solver.positions[cloth.particleIndices[e.particleIndex]], Quaternion.identity);
Debug.Log("2");
}
}
}