Example #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.Mouse0) && main.gameObject.activeSelf && canShoot && newCanShoot)
        {
            float rotation = (rb.rotation + 90);
            if (weapon.GetComponent <Weapon>().Shoot(transform.Find("Barrel").position, new Vector2(Mathf.Cos(((rotation) * Mathf.PI) / 180), Mathf.Sin(((rotation) * Mathf.PI) / 180)), gameObject.GetComponent <Rigidbody2D>().velocity))
            {
                audioManager.Play("LazerShoot");
            }
        }

        if (Input.GetKey("f") && hasSheilds && canSheild && sheilding == false)
        {
            timeToReclick = .25f;
            sheild       -= shieldConsumption;
            sheildBar.GetComponent <RectTransform>().localScale = new Vector3(sheild / maxSheild,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.y,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.z);
            sheilding = true;
            canSheild = false;
            sheildGameObject.SetActive(true);
        }

        else if (Input.GetKey("f") && hasSheilds && !canSheild && sheilding && timeToReclick <= 0)
        {
            sheilding = false;
            sheildGameObject.SetActive(false);
        }

        if (sheilding && hasSheilds && !canSheild)
        {
            timeToReclick -= Time.deltaTime;
            sheild        -= shieldConsumption;
            sheildBar.GetComponent <RectTransform>().localScale = new Vector3(sheild / maxSheild,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.y,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.z);
        }


        if (sheild <= 0 && sheilding && hasSheilds)
        {
            sheilding = false;
            sheildGameObject.SetActive(false);
        }


        if (sheilding == false && canSheild == false && hasSheilds)
        {
            if (fasterCooldown)
            {
                sheild += sheildRegenRate * 1.2f;
            }
            else
            {
                sheild += sheildRegenRate;
            }
            if (sheild >= maxSheild)
            {
                sheild    = maxSheild;
                canSheild = true;
            }

            sheildBar.GetComponent <RectTransform>().localScale = new Vector3(sheild / maxSheild,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.y,
                                                                              sheildBar.GetComponent <RectTransform>().localScale.z);
        }

        if (Input.GetKey("m") && MaxItemsManager.mineAmount > 0 && timeBeforeNextMine <= 0)
        {
            GameObject mineObject = Instantiate(mine);
            mineObject.transform.position = transform.Find("MineSpawn").position;

            MaxItemsManager.useMine();
            mineAmountText.GetComponent <Text>().text = "x" + MaxItemsManager.mineAmount;
            timeBeforeNextMine = timeBetweenMines;
        }
        timeBeforeNextMine -= Time.deltaTime;
    }