// Update is called once per frame
    void Update()
    {
        if (field == null)
        {
            return;
        }

        var dist = field.distance(transform.position);

        transform.localScale = 2f * Mathf.Abs(dist.w) * Vector3.one;
        _mat.color           = (dist.w > 0f ? Color.red : Color.blue);
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (_shuriken.maxParticles <= _shuriken.particleCount)
        {
            return;
        }

        var pos  = radius * Random.insideUnitSphere;
        var dist = _distanceField.distance(pos);

        if (dist.w > 0)
        {
            return;
        }

        _shuriken.Emit(pos, Vector3.zero, 2.0f * Mathf.Abs(dist.w), _shuriken.startLifetime, Color.white);
    }
    // Update is called once per frame
    void Update()
    {
        if (_system.particleCount > _particles.Length)
        {
            int powerOfTwo = (int)Mathf.Ceil(Mathf.Log10(_system.particleCount) * _log2Inv);
            int n          = (int)Mathf.Pow(2, powerOfTwo);
            _particles = new ParticleSystem.Particle[n];
        }
        int   nParticles = _system.GetParticles(_particles);
        float dt         = Time.deltaTime;

        for (int i = 0; i < nParticles; i++)
        {
            ParticleSystem.Particle p = _particles[i];
            Vector4 dist      = distField.distance(p.position);
            Vector3 forceDist = (dist.w > 0 ? coeffForceDist * (Vector3)dist : Vector3.zero);
            Vector3 force     = forceDist;
            p.velocity   += dt * force;
            p.size        = Mathf.Abs(dist.w);
            _particles[i] = p;
        }

        _system.SetParticles(_particles, nParticles);
    }