Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (Exp >= ExpMax)
     {
         LevelUp(Exp - ExpMax);
     }
     if (Input.GetKey(KeyCode.U))
     {
         LevelUp(0);
     }
     Constant = Time.deltaTime * 60;
     if (contacts.Count <= 0)
     {
         CanJump = false;
     }
     if (Health <= 0)
     {
         Die();
     }
     if (Input.GetKey("return") && !Weapon.GetComponent <WeaponScript>().Swinging&& Weapon.GetComponent <WeaponScript>().CanSwing&&CanSwing)
     {
         Weapon.GetComponent <WeaponScript>().Swing();
     }
     if (Input.GetKey("left shift"))
     {
         Sprinting = true;
     }
     else
     {
         Sprinting = false;
     }
     if (Input.GetKeyDown("s"))
     {
         DownJump();
     }
     if (Input.GetKeyDown("k"))
     {
         SkillUi.gameObject.GetComponent <Canvas>().enabled = !SkillUi.gameObject.GetComponent <Canvas>().enabled;
     }
     if (dodging)
     {
         GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0.5f);
     }
     else
     {
         GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 1);
     }
     if (Input.GetKeyDown("q"))
     {
         QuestUi.gameObject.GetComponent <Canvas>().enabled = !QuestUi.gameObject.GetComponent <Canvas>().enabled;
         if (!QuestUi.gameObject.GetComponent <Canvas>().enabled)
         {
             QuestUi.CloseQuests();
         }
         else
         {
             QuestUi.RefreshQuests();
         }
     }
     if (Input.GetKeyDown("e"))
     {
         if (!dialogmanager.InTrade && !dialogmanager.InShop)
         {
             InventoryUi.gameObject.GetComponent <InventoryUiScript>().Inventory.transform.localPosition = new Vector3(0, -200, 0);
             if (InventoryUi.enabled == false)
             {
                 InventoryUi.gameObject.GetComponent <InventoryUiScript>().RefreshInventory();
             }
             else
             {
                 InventoryUi.gameObject.GetComponent <InventoryUiScript>().CloseInventory();
             }
             InventoryUi.enabled = !InventoryUi.enabled;
         }
         else
         {
             dialogmanager.InTrade = false;
             dialogmanager.InShop  = false;
             SellUi.CloseSellInventory();
             SellUi.gameObject.GetComponent <Canvas>().enabled = false;
             BuyUi.CloseBuyInventory();
             BuyUi.gameObject.GetComponent <Canvas>().enabled = false;
         }
     }
     if (!InUi)
     {
         if (Input.GetKey("a") && !Input.GetKey("d") && !dodging)
         {
             dir = 1;
             if (CanJump)
             {
                 Moving = true;
             }
             if (Sprinting && CanJump)
             {
                 GetComponent <Rigidbody2D>().AddForce(-transform.right * speed * 1.5f * Constant, ForceMode2D.Force);
             }
             else
             {
                 GetComponent <Rigidbody2D>().AddForce(-transform.right * speed * Constant, ForceMode2D.Force);
             }
             transform.localScale = new Vector3(-1, 1, 1);
         }
         if (Input.GetKey("d") && !Input.GetKey("a") && !dodging)
         {
             dir = -1;
             if (CanJump)
             {
                 Moving = true;
             }
             if (Sprinting && CanJump)
             {
                 GetComponent <Rigidbody2D>().AddForce(transform.right * speed * 1.5f, ForceMode2D.Force);
             }
             else
             {
                 GetComponent <Rigidbody2D>().AddForce(transform.right * speed, ForceMode2D.Force);
             }
             transform.localScale = new Vector3(1, 1, 1);
         }
     }
     if (Input.GetKey("space") || Input.GetKey("w"))
     {
         if (CanJump && !JumpCool)
         {
             StartCoroutine(JumpCooldown());
             if (OnBed && transform.position.y > -1.77)
             {
                 GetComponent <Rigidbody2D>().AddForce(transform.up * 20, ForceMode2D.Impulse);
                 source.PlayOneShot(bedbounce);
             }
             else
             {
                 GetComponent <Rigidbody2D>().AddForce(transform.up * 13, ForceMode2D.Impulse);
                 source.clip = jump;
                 source.Play();
             }
             CanJump = false;
             OnBed   = false;
         }
     }
     if (!CanJump)
     {
         GetComponent <Rigidbody2D>().AddForce(-transform.up * 12, ForceMode2D.Force);
         Moving = false;
     }
     if (!Moving)
     {
         GetComponent <SpriteRenderer>().sprite = sprites[0];
     }
     if (!Input.GetKey("a") && !Input.GetKey("d"))
     {
         Moving = false;
     }
     if (RemainingCombat > 0)
     {
         InCombat = true;
     }
     else
     {
         InCombat = false;
     }
     if (codeindex != 10)
     {
         if (Input.GetKeyDown(code[codeindex]))
         {
             codeindex += 1;
         }
     }
     else
     {
         codeindex = 0;
         AddToInventory(ItemManager.registereditems[2], 1);
     }
     if (Input.GetKey("m") && Input.GetKey("k"))
     {
         codeindex = 0;
     }
     if (Input.GetKeyDown("f") && HealthPotions >= 1)
     {
         inventory[HPotIndex].amount -= 1;
         source.PlayOneShot(BottleSound);
         HPotNum  += 1;
         HPotTimer = 2;
         if (Health <= (MaxHealth - PotEffect))
         {
             Health += PotEffect;
         }
         else
         {
             Health = MaxHealth;
         }
     }
     if (Input.GetKeyDown("v") && ManaPotions >= 1)
     {
         inventory[MPotIndex].amount -= 1;
         source.PlayOneShot(BottleSound);
         if (Mana <= (MaxMana - 20))
         {
             Mana += 20;
         }
         else
         {
             Mana = MaxMana;
         }
     }
     if (HPotTimer >= Time.deltaTime)
     {
         HPotTimer -= Time.deltaTime;
     }
     else
     {
         HPotTimer = 0;
     }
     if (HPotTimer == 0)
     {
         HPotNum = 0;
     }
     PotEffect = Mathf.Clamp(20 - HPotNum, 5, 20);
     Sift();
     HandleSkillInput();
 }