コード例 #1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Interactable")
     {
         if (interactableItem == null)
         {
             var test = collision.gameObject.GetComponent <ItemPrefab>();
             if (test != null)
             {
                 test.interact(this);
             }
             else
             {
                 interactableItem = collision.gameObject.GetComponent <Interactable>();
                 if (interactableItem != null)
                 {
                     interactableItem.CanBeInteract(true);
                 }
             }
         }
     }
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (!Menu.inGame || Inventory.Instance.IsInInventory())
        {
            if (spriteManager.update)
            {
                clipWalk.Stop();
                spriteManager.stop();
                isMoving = false;
            }
            return;
        }


        if (!isLose && !combatComponent.isDead)
        {
            if (Input.GetButtonDown("Interact") && interactableItem != null)
            {
                //interact = true;
                if (interactableItem.interact(this))
                {
                    if (interactableItem != null)
                    {
                        interactableItem.CanBeInteract(false);
                        interactableItem = null;
                    }
                }
                //interact = false;
            }
            else if (Input.GetButtonDown("Fight") && combatComponent.CanAttack)
            {
                combatComponent.Attack(dir);
                bloodLustComponent.addBloodLust(attackBloodLustCost);
                if (spriteManager.update)
                {
                    clipWalk.Stop();
                    spriteManager.stop();
                    //isMoving = false;
                }
            }
            else if (!combatComponent.isAttacking)
            {
                if (checkLevel())
                {
                    DisplayLoseScreen("Your Lycanthropy level As reach 100% you Lose ");
                }
                else
                {
                    float inputX = Input.GetAxis("Horizontal");
                    float inputY = Input.GetAxis("Vertical");
                    movement = new Vector3(inputX, inputY).normalized;
                    if (movement.magnitude > 0)
                    {
                        isMoving = true;
                        dir      = DirectionEnumMethods.GetDirection(movement);
                        spriteManager.ActualDir = dir;

                        float run = Input.GetAxis("Run");


                        //transform.position = transform.position + movement * Time.deltaTime * (((1 - run) * speed) + (run * runSpeed));
                        movement *= /* Time.deltaTime * */ (((1 - run) * speed) + (run * runSpeed));
                        if (run == 1)
                        {
                            bloodLustComponent.addBloodLust(runBloodLustCost * Time.deltaTime);
                        }

                        if (!spriteManager.update)
                        {
                            isMoving = true;
                            spriteManager.start();
                            clipWalk.Play();
                        }

                        spriteManager.Update();
                    }
                    else
                    if (spriteManager.update)
                    {
                        isMoving = false;
                        clipWalk.Stop();
                        spriteManager.stop();
                    }
                }
            }
        }
        else
        {
            if (!isLose)
            {
                DisplayLoseScreen("Your life as reach 0");
            }
        }
    }