// Update is called once per frame void Update() { // Update transform m_top -= 0.8f * speed * Vector3.up; SetTransform(m_top, m_bottom); // Raycast down RaycastHit hit; // if ( Physics.Raycast(m_top, Vector3.down, out hit, (m_top.y - m_bottom.y) * speed)) if (Physics.Raycast(m_bottom, Vector3.down, out hit, speed)) { if (effectPrefab) { effectPrefab.AddEffectTo(hit.collider.gameObject); } // If hits a liquid container WithLiquid wl = hit.collider.gameObject.GetComponent <WithLiquid>(); if (wl) { float delta = Mathf.Min(0.5f * speed, m_liquidVolume); wl.Fill(delta); m_liquidVolume -= delta; } } else { m_bottom -= speed * Vector3.up; } // Destroyed when the top reachs the ground if (m_top.y <= m_bottom.y) { Destroy(gameObject); } }
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e) { foreach (Oni.Contact contact in e.contacts) { // this one is an actual collision: if (contact.distance < 0.01) { Component component; if (ObiCollider.idToCollider.TryGetValue(contact.other, out component)) { ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle]; ObiEmitter emitter = pa.actor as ObiEmitter; if (emitter != null && emitter.life[pa.indexInActor] > 0f) { WithLiquid wl = component.gameObject.GetComponent <WithLiquid>(); if (wl) { if (wl.Fill(WithLiquid.volumePerParticle)) { emitter.life[pa.indexInActor] = 0; } } else { Effect effect = pa.actor.GetComponent <Effect>(); if (effect && effect.AddEffectTo(component.gameObject)) { emitter.life[pa.indexInActor] = 0; } } } } } } }