Example #1
0
File: Fan.cs Project: ajweeks/NJ01
    void Update()
    {
        float stickSpeed     = Mathf.Abs(ControllingValve.GetAverageStickSpeed());
        float stickSpeedMult = Mathf.Clamp01(Mathf.Max(stickSpeed - _minStickSpeed, 0.0f) / (_maxStickSpeed - _minStickSpeed));

        _projectilesInAirStream.ForEach(projectile =>
        {
            projectile.vel = new Vector3(
                _airFlowDir.x * AirFlowSpeed * stickSpeedMult,
                0,
                _airFlowDir.z * AirFlowSpeed * stickSpeedMult);

            if (stickSpeedMult < 0.1f)
            {
                projectile.y += _fallMultiplier * Time.deltaTime;
            }

            projectile.obj.transform.position = new Vector3(
                projectile.obj.transform.position.x + projectile.vel.x * Time.deltaTime,
                projectile.y,
                projectile.obj.transform.position.z + projectile.vel.z * Time.deltaTime);
        });

        for (int i = _projectilesInAirStream.Count - 1; i >= 0; i--)
        {
            if (_projectilesInAirStream[i].obj.GetComponent <Projectile>().HitTrigger)
            {
                _projectilesInAirStream[i].obj.GetComponent <Rigidbody>().useGravity = true;
                _projectilesInAirStream.RemoveAt(i);
            }
        }
    }