Esempio n. 1
0
    public void Start()
    {
        if (_initialised)
        {
            return;
        }
        _initialised = true;

        OriginalSpeed = Speed;

        Debug.Log("Starting surfboard");
        Initialise();

        GetComponent <CharacterController>().enabled = false;

        // Setup tweaks to the water particle systems we have
        emitters     = GetComponentsInChildren <ParticleEmitter>();
        minParticles = new float[emitters.Length];
        maxParticles = new float[emitters.Length];
        minSize      = new float[emitters.Length];
        maxSize      = new float[emitters.Length];

        for (int i = 0; i < emitters.Length; i++)
        {
            ParticleEmitter emitter = emitters[i];

            minParticles[i] = emitter.minEmission;
            maxParticles[i] = emitter.maxEmission;
            minSize[i]      = emitter.minSize;
            maxSize[i]      = emitter.maxSize;
        }
    }
Esempio n. 2
0
    protected void FixedUpdate()
    {
        SyncStateWithWorld();

        for (int i = 0; i < emitters.Length; i++)
        {
            ParticleEmitter emitter = emitters[i];

            if (emitter.enabled && !Active)
            {
                emitter.ClearParticles();
            }

            emitter.enabled = Active;

            float magnitude = 1f;

            var cc = GetComponent <CharacterController>();

            if (cc.velocity.magnitude < 1f)
            {
                magnitude = 0f;
            }
            else
            {
                magnitude = cc.velocity.magnitude;
            }

            magnitude /= 5f;

            emitter.minEmission = minParticles[i] * magnitude;
            emitter.maxEmission = minParticles[i] * magnitude;
            emitter.minSize     = minSize[i] * Mathf.Clamp01(magnitude);
            emitter.maxSize     = maxSize[i] * Mathf.Clamp01(magnitude);
        }
    }