r/UnityHelp • • Jun 21 '22

C# script doesn't work as intended.

I'm trying to make a script where if a particle from a fluid simulation asset hits a game object, it deletes it. I don't get any compiler errors from it but cant seem to figure out why it isn't working.

I'm new to Unity and C# in general so I might have screwed up some simple thing.

Obi is the Fluid simulation asset.

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class somethig : MonoBehaviour
{
ObiSolver solver;  

ObiSolver.ObiCollisionEventArgs collisionEvent;

public GameObject Cement_Floor;
void Awake()
    {
solver = GetComponent<ObiSolver>();
    }
void OnEnable()
    {
solver.OnCollision += Solver_OnCollision;
    }
void OnDisable()
    {
solver.OnCollision -= Solver_OnCollision;
    }

void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {

var world = ObiColliderWorld.GetInstance();
foreach (Oni.Contact contact in e.contacts)
        {
// this one is an actual collision:
if (contact.distance < 0.01)
            {
Destroy(Cement_Floor);
            }
        }
    }
}

Thanks for the help!

2 Upvotes

1 comment sorted by

1

u/cone5000 Jul 02 '22

In case you haven’t figured this out, it should probably be Destroy(Cement_Floor.gameObject)