예제 #1
0
    public GameObject SpawnOtherWpn(int num)
    {
        Debug.Log("I built a gun");
        GameObject     newWpn = Instantiate(PersistantSettings.weaponList[num], transform.GetChild(6));
        weaponMovement script = newWpn.GetComponent <weaponMovement>();

        if (!isLocalPlayer)
        {
            script.enabled = false;
        }
        else
        {
            script.thisMulti = this;
            script.thisInput = (input)localComponents[1];
            cameraSpotHandler thisHandler = (cameraSpotHandler)localComponents[9];
            thisHandler.spotR = newWpn.transform.GetChild(0);
        }



        gameObject.GetComponent <NetworkTransformChild>().target = newWpn.transform;
        weaponGraph[0] = newWpn.GetComponent <graphicCordinator>();
        Debug.Log("odebral gracz: " + RemnetId + " od gracza ");

        //Vector3 positionOf = PersistantSettings.chosenWpn.prefab.transform.localPosition;
        //PersistantSettings.chosenWpn.prefab.transform.parent = transform.GetChild(6);
        //PersistantSettings.chosenWpn.prefab.transform.localPosition = positionOf;
        //localComponents[11] = PersistantSettings.chosenWpn.script;



        return(newWpn);
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (highArmorPurchased == false && lowArmorPurchased == false)
        {
            clothPlayer = true;
        }

        bowCooldown.fillAmount   = bowShoot / maxBowShoot;
        magicCooldown.fillAmount = magicShoot / maxMagicShoot;

        if (Input.GetKeyDown("1") && swordPurchased == true)
        {
            swordSelected.SetActive(true);
            bowSelected.SetActive(false);
            magicSelected.SetActive(false);
        }

        if (Input.GetKeyDown("2") && bowPurchased == true)
        {
            bowSelected.SetActive(true);
            swordSelected.SetActive(false);
            magicSelected.SetActive(false);
        }

        if (Input.GetKeyDown("3") && magicPurchased == true)
        {
            bowSelected.SetActive(false);
            swordSelected.SetActive(false);
            magicSelected.SetActive(true);
        }

        // Using Bow
        if (bowSelected.activeInHierarchy)
        {
            swordObject.SetActive(false);
            bowObject.SetActive(true);
            magicObject.SetActive(false);
            magicCooldown.fillAmount = 0;


            playerDamage = bowDamage * playerDamageModifier;
            attackPos    = bowAttack;
            damageTook   = playerDamage;

            if (bowShoot <= 0)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Vector2 target         = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
                    Vector2 playerPosition = new Vector2(transform.position.x + 0.2f, transform.position.y + 0.8f);
                    Vector2 direction      = target - playerPosition;
                    direction.Normalize();
                    Quaternion rotation    = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg);
                    GameObject projectiles = (GameObject)Instantiate(projectile, playerPosition, rotation);
                    projectiles.GetComponent <Rigidbody2D>().velocity = direction * speed;
                    bowShoot = maxBowShoot;
                }
            }
            else
            {
                bowShoot -= Time.deltaTime;
            }
        }

        //Using Sword
        if (swordSelected.activeInHierarchy)
        {
            swordObject.SetActive(true);
            bowObject.SetActive(false);
            magicObject.SetActive(false);
            magicCooldown.fillAmount = 0;
            bowCooldown.fillAmount   = 0;

            playerDamage = swordDamage * playerDamageModifier;
            attackPos    = swordAttack;
            damageTook   = playerDamage;

            weaponMovement weaponTimer = GetComponentInChildren <weaponMovement>();

            if (weaponTimer.swordSwingtime <= 0)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(swordAttack.position, attackRange, whoIsEnemy);


                    for (int i = 0; i < enemiesToDamage.Length; i++)
                    {
                        enemiesToDamage[i].GetComponent <enemyController>().TakeDamage(damageTook);
                        Instantiate(hitEffect, enemiesToDamage[i].transform.position, Quaternion.identity);
                        Debug.Log("Hit Enemy With Sword");
                    }
                }
            }

            /* if (Input.GetMouseButtonDown(0))
             * {
             *   Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(swordAttack.position, attackRange, whoIsEnemy);
             *
             *
             *   for (int i = 0; i < enemiesToDamage.Length; i++)
             *   {
             *       enemiesToDamage[i].GetComponent<enemyController>().TakeDamage(damageTook);
             *       Instantiate(hitEffect, enemiesToDamage[i].transform.position, Quaternion.identity);
             *       Debug.Log("Hit Enemy With Sword");
             *   }
             *
             *
             * }*/
        }

        //Using Magic
        if (magicSelected.activeInHierarchy)
        {
            swordObject.SetActive(false);
            bowObject.SetActive(false);
            magicObject.SetActive(true);
            bowCooldown.fillAmount   = 0;
            swordCooldown.fillAmount = 0;


            playerDamage = magicDamage * playerDamageModifier;
            attackPos    = magicAttack;
            damageTook   = playerDamage;

            if (magicShoot <= 0)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Vector2 target         = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
                    Vector2 playerPosition = new Vector2(transform.position.x + 0.2f, transform.position.y + 1.2f);
                    Vector2 direction      = target - playerPosition;
                    direction.Normalize();
                    Quaternion rotation  = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg);
                    GameObject magicBeam = (GameObject)Instantiate(magicShot, playerPosition, rotation);
                    magicBeam.GetComponent <Rigidbody2D>().velocity = direction * magicSpeed;
                    magicShoot = maxMagicShoot;
                }
            }
            else
            {
                magicShoot -= Time.deltaTime;
            }
        }

        if (Input.GetKeyDown(KeyCode.R) && potionPurchased == true)
        {
            if (potionAmount > 0)
            {
                potionAmount -= 1;
                drinkSound.GetComponent <soundRandomizer>().PlayActive();
                Instantiate(drinkEffect, transform.position, Quaternion.identity);
                potionText.text = potionAmount.ToString();
                GetComponent <healthBar>().health += 3;
            }
        }

        anim.SetBool("gotLight", lowArmorPurchased);
        anim.SetBool("gotHeavy", highArmorPurchased);
    }