01-05-2019, 12:34 AM
(This post was last modified: 01-05-2019, 12:34 AM by josemendez.)
(30-04-2019, 03:52 PM)Richard Wrote: I asked almost same question, but I could not get sign of when it is torn. I want an example to achieve.
Hi,
You already asked this same question, and a complete example was provided. See:
http://obi.virtualmethodstudio.com/forum...t=callback
This is the sample code. Simply subscribe a function to the cloth's OnConstraintTorn callback. That's all there is to it:
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiTearableCloth))]
public class ClothTornEvent : MonoBehaviour {
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)
{
if (thingToSpawn != null)
GameObject.Instantiate(thingToSpawn,cloth.Solver.positions[cloth.particleIndices[e.particleIndex]],Quaternion.identity);
}
}