private IEnumerator EmitWater()
    {
        while (true)
        {
            yield return(new WaitForSeconds(interval));

            foreach (var emitter in emitters)
            {
                var position  = Vector2.Lerp(emitter.v0, emitter.v1, Random.Range(0f, 1f));
                var direction = Vector2.Perpendicular(emitter.v0 - emitter.v1);
                if (Vector2.Dot(direction, position) > 0)
                {
                    direction *= -1;
                }
                var directionNormalized = direction.normalized;
                fluidSystem.EmitWater(position + 0.2f * directionNormalized, Random.Range(3f, 6f) * directionNormalized);
            }
        }
    }
예제 #2
0
 private void Update()
 {
     if (Input.GetMouseButton(0))
     {
         Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f);
         Vector3 viewPos  = _camera.ScreenToViewportPoint(mousePos);
         if (viewPos.x > 0 && viewPos.x < 1 && viewPos.y > 0 && viewPos.y < 1)
         {
             Vector3 wordPos = _camera.ScreenToWorldPoint(mousePos);
             for (int i = 0; i < count; i++)
             {
                 Vector3 position = wordPos + UnityEngine.Random.insideUnitSphere * radius;
                 position.z = 0f;
                 fluidSystem.EmitWater(position, Vector2.zero);
             }
         }
     }
     if (Input.GetMouseButton(1))
     {
         Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f);
         Vector3 viewPos  = _camera.ScreenToViewportPoint(mousePos);
         if (viewPos.x > 0 && viewPos.x < 1 && viewPos.y > 0 && viewPos.y < 1)
         {
             Vector3 wordPos = _camera.ScreenToWorldPoint(mousePos);
             for (int i = 0; i < count; i++)
             {
                 Vector3 position = wordPos + UnityEngine.Random.insideUnitSphere * radius;
                 position.z = 0f;
                 fluidSystem.EmitSteam(position, Vector2.zero);
             }
         }
     }
     if (Input.GetMouseButtonDown(2))
     {
         Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f);
         Vector3 viewPos  = _camera.ScreenToViewportPoint(mousePos);
         if (viewPos.x > 0 && viewPos.x < 1 && viewPos.y > 0 && viewPos.y < 1)
         {
             Vector3 wordPos = _camera.ScreenToWorldPoint(mousePos);
             fluidSystem.EmitExplosion(wordPos, explosionForce, explosionLifeTime);
         }
     }
 }