コード例 #1
0
ファイル: PlayerHit.cs プロジェクト: tobbep1997/Yggdrasill
    private void Update()
    {
        if (dead && !other.dead)
        {
            timer += Time.deltaTime;
            if (timer > time)
            {
                other.dead = true;

                other.Hit();
            }
        }
    }
コード例 #2
0
    // interacting with physical objects in the world
    private bool UseToolWorld()
    {
        if (Time.timeScale == 0)
        {
            return(false);
        }

        // CUTTING TREE
        Vector2 position = rgbd2d.position + character.lastMotionVector * offsetDistance;

        Collider2D[] colliders = Physics2D.OverlapCircleAll(position, sizeOfInteractableArea);


        foreach (Collider2D collidor in colliders)
        {
            ToolHit     hitTree   = collidor.GetComponent <ToolHit>();
            CampFireHit hitFire   = collidor.GetComponent <CampFireHit>();
            ChestHit    hitChest  = collidor.GetComponent <ChestHit>();
            PlayerHit   hitPlayer = collidor.GetComponent <PlayerHit>();

            if (hitTree != null && toolbarController.GetItem != null &&
                toolbarController.GetItem.Name == "Axe" && CastRay() == true)
            {
                hitTree.Hit();
                // Debug.Log("we can hit");
                return(true);
            }
            if (hitFire != null && toolbarController.GetItem != null &&
                toolbarController.GetItem.Name == "Wood" && CastRay() == true)
            {
                hitFire.Hit();
                return(true);
            }
            if (hitChest != null && CastRay() == true)
            {
                hitChest.Hit();
                return(true);
            }
            if (hitPlayer != null && toolbarController.GetItem != null && CastRayPlayer() == true && (toolbarController.GetItem.Name == "Food_Corn" || toolbarController.GetItem.Name == "Food_Parsley" ||
                                                                                                      toolbarController.GetItem.Name == "Food_Potato" || toolbarController.GetItem.Name == "Food_Strawberry" || toolbarController.GetItem.Name == "Food_Tomato"))
            {
                hitPlayer.Hit();
                return(true);
            }
        }

        return(false);
    }