Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi tearable cloth
#6
(01-05-2019, 11:42 AM)Richard Wrote: 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");
       }
           
   }
}
However, I could not see "1" or "2" when the cloth is tore.  I need another thing? How can I get input from obi tearable cloth?

Maybe not disabling your component immediately in Start() would work Guiño
Reply


Messages In This Thread
Obi tearable cloth - by Richard - 30-04-2019, 03:52 PM
RE: Obi tearable cloth - by josemendez - 01-05-2019, 12:34 AM
RE: Obi tearable cloth - by Richard - 01-05-2019, 01:37 AM
RE: Obi tearable cloth - by josemendez - 01-05-2019, 09:50 AM
RE: Obi tearable cloth - by Richard - 01-05-2019, 11:42 AM
RE: Obi tearable cloth - by josemendez - 01-05-2019, 11:52 AM
RE: Obi tearable cloth - by Richard - 01-05-2019, 12:05 PM