private GameObject FireAltoInstance; // instanza del prefab firealto


    // Start is called before the first frame update
    void Start()
    {
        // inizializzazione
        xController   = GetComponent <CharacterController>();
        xAnimator     = GetComponent <Animator>();
        xAudioManager = FindObjectOfType <SoundManager>();
        xFXManager    = FindObjectOfType <FXManager>();
        xGunShotFX    = xFXManager.FindFXParticle("FX_Gunshot");
        xSmokeFX      = xFXManager.FindFXParticle("FX_Smoke");
        xStaccoFX     = xFXManager.FindFXParticle("FX_Stacco");

        xTimeStart      = -1;
        FuriaTimeStatus = -1;
        FuriaStatus     = eFuriaStatus.NORMAL;
        xAudioManager.Play("YEAH", 0.20f);
    }
    // Update is called once per frame
    void Update()
    {
        xTimeCurrent = Time.time;

        // true = contatto con ground
        isGround = xController.isGrounded;

        // dimensione attuale del player
        xFuriaDimStart = xController.transform.localScale;
        // posizione attuale del player
        xFuriaPosition = xController.transform.position;


        // ** GROUND ********************************************
        if (isGround)
        {
            if ((xTimeStart == -1) || ((xTimeCurrent - xTimeStart) > 0.5))
            {
                PlayerStatus = ePlayerStatus.Ground;
            }
            xTimeStart = -1;
        }

        // ** JUMP ********************************************
        if (PlayerStatus == ePlayerStatus.Ground && Input.GetButtonDown("JUMP"))
        {
            xTimeStart   = -1;
            PlayerStatus = ePlayerStatus.Jump;
            xAnimator.Play("Player.JUMP", 0, 1f);
            xStaccoFX.Play();
            xAudioManager.Play("JUMP2", 0);
            xAudioManager.Play("URLO", 2f);
        }

        // ** FIRE ********************************************
        if (PlayerStatus == ePlayerStatus.Ground && Input.GetButtonDown("FIRE"))
        {
            xTimeStart   = xTimeCurrent;
            PlayerStatus = ePlayerStatus.Fire;
            xaggiunta    = this.transform.lossyScale;
            xposWeaponFX = new Vector3(this.transform.position.x + 1, this.transform.position.y + xaggiunta.y, BulletObject.transform.position.z);
            Bullet       = Instantiate(BulletObject, xposWeaponFX, BulletObject.transform.rotation);
            xAnimator.Play("Player.FIRE", 0, 0.1f);
            xAudioManager.Play("STACCO", 0);
            xAudioManager.Play("FIRE", 0.2f);
            xSmokeFX.Play();
            xGunShotFX.Play();
        }

        // ** FIRE ALTO ********************************************
        if (PlayerStatus == ePlayerStatus.Ground && Input.GetButtonDown("FIREALTO"))
        {
            //if (!ExplosionInstance)
            xTimeStart   = -1;
            PlayerStatus = ePlayerStatus.FireAlto;
            xStaccoFX.Play();
            xAnimator.Play("Player.FIREALTO", 0, 1f);
            xAudioManager.Play("STACCO", 0);
            xAudioManager.Play("FIREALTO", 0.9f);
            xaggiunta        = this.transform.lossyScale;
            FireAltoInstance = Instantiate(FireAltoObject, this.transform);
            xposWeaponFX     = new Vector3(FireAltoInstance.transform.position.x, FireAltoInstance.transform.position.y + (xaggiunta.y * -1f), FireAltoInstance.transform.position.z);
            FireAltoInstance.transform.position = xposWeaponFX;
        }

        // ** RELOAD ********************************************
        if (PlayerStatus == ePlayerStatus.Ground && Input.GetButtonDown("RELOAD"))
        {
            xTimeStart   = -1;
            PlayerStatus = ePlayerStatus.Reload;
            xAnimator.Play("Player.RELOAD", 0, 3f);
            xAudioManager.Play("STACCO", 0);
            xAudioManager.Play("RELOAD", 0.5f);
        }


        // ** FURIA********************************************
        if (PlayerStatus == ePlayerStatus.Ground)
        {
            if ((FuriaTimeStatus == -1) && (FuriaStatus == eFuriaStatus.NORMAL))
            {
                if (Input.GetButtonDown("FURIA"))
                {
                    xTimeStart      = -1;
                    FuriaTimeStatus = xTimeCurrent;
                    PlayerStatus    = ePlayerStatus.Furia;
                    xAnimator.Play("Player.FURIA", 0, 1f);
                    xAudioManager.Play("STACCO", 0);
                    xStaccoFX.Play();
                }
            }
        }
        // NORMAL --> BIG
        if ((FuriaTimeStatus != -1) && (FuriaStatus == eFuriaStatus.NORMAL))
        {
            if ((xTimeCurrent - FuriaTimeStatus) < FuriaTime)
            {
                if (xFuriaDimStart.y < 2.00000000001)
                {
                    xFuriaDimEnd = new Vector3(2f, 2f, 2f);
                    xController.transform.localScale += (xFuriaDimEnd * Time.deltaTime);
                }
                if (xFuriaPosition.x < -17)
                {
                    xMovement.x = 1f;
                    xController.Move(xMovement * Time.deltaTime);
                    //xController.transform.position += (xMovement * Time.deltaTime);
                }
            }
            else
            {
                FuriaTimeStatus = xTimeCurrent;
                FuriaStatus     = eFuriaStatus.BIG;
            }
        }
        // BIG --> NORMAL
        if ((FuriaTimeStatus != -1) && (FuriaStatus == eFuriaStatus.BIG))
        {
            if ((xTimeCurrent - FuriaTimeStatus) < (FuriaTime * 2))
            {
                if (xFuriaDimStart.y > 1.00000000001)
                {
                    xFuriaDimEnd = new Vector3(1f, 1f, 1f);
                    xController.transform.localScale -= (xFuriaDimEnd * Time.deltaTime);
                }
                if (xFuriaPosition.x > -22.33)
                {
                    xMovement.x = -1f;
                    xController.Move(xMovement * Time.deltaTime);
                    //xController.transform.position += (xMovement * Time.deltaTime);
                }
            }
            else
            {
                FuriaTimeStatus = -1;
                FuriaStatus     = eFuriaStatus.NORMAL;
            }
        }


        // ** FIRE3 ********************************************



        // sposto leggermente in su per staccarlo dal ground..il primo frame
        if (PlayerStatus != ePlayerStatus.Ground)
        {
            yMovement.y = 0.01f;
            xController.Move(yMovement);
        }


        // se indietro (per esempio urtando nuvola)
        // lo riporto al solito posto
        if (xFuriaPosition.x < -22.33f)
        {
            xMovement.x = 1f;
            xController.Move(xMovement * Time.deltaTime);
        }
    }