Exemplo n.º 1
0
    void Start()
    {
        if (verboseMode)
        {
            Debug.Log("[ObjectManager] Start");
        }

        raccoon = GameManager.instance.Raccoon;

        startUp = true;
    }
Exemplo n.º 2
0
    public void Equip(TrashManiaDisplay display)
    {
        // Called
        rb                      = GetComponent <Rigidbody>();
        playerScript            = GameManager.instance.Raccoon.GetComponent <RaccoonController>();
        rb.isKinematic          = true;
        beingCarried            = true;
        transform.parent        = playerScript.transform;
        transform.localPosition = playerScript.transform.forward;
        var offset = playerScript.transform.right * -0.5f;

        offset.y = 0;
        transform.localPosition += offset;
        // playerScript.AddStrengthModifier(effectOnAttack, 0);

        timer = timerLength;
        Debug.Log(ObjectManager.instance);
        ObjectManager.instance.EquipTool(this);
        this.trashManiaDisplay = display;
        trashManiaDisplay.gameObject.SetActive(true);
        trashManiaDisplay.Enable(this);
    }
Exemplo n.º 3
0
    void Update()
    {
        //if (verboseMode) Debug.Log("[ObjectManager] Update");

        if (!raccoon)
        {
            if (!GameManager.instance.Raccoon)
            {
                if (verboseMode)
                {
                    Debug.Log("[ObjectManager] No Raccon");
                }
                return;
            }
            else
            {
                raccoon = GameManager.instance.Raccoon;
            }
        }

        // reset target and in range
        DisableHighlight(target);
        target = null;
        foreach (var k in inRangeKnockables)
        {
            DisableHighlight(k);
        }
        inRangeKnockables.Clear();

        // Update target & in range, in range at every frame using raycast
        RaycastHit hit;

        // Bottom of controller. Slightly above ground so it doesn't bump into slanted platforms.
        Vector3 p1 = raccoon.transform.position - Vector3.up * 0.20f;
        Vector3 p2 = p1 + Vector3.up * raccoon.charController.height;
        var     raycastPaddedDist = raccoon.charController.radius + raycastPadding;

        // Update target
        // try to find the closest target
        var targetDist = raycastPaddedDist + 1;

        for (float i = -3.14f; i < 3.14; i += 0.02f)
        {
            var dir = raccoon.transform.TransformDirection(Vector3.forward) * 5 + new Vector3(Mathf.Cos(i), 0, Mathf.Sin(i));

            // knockable layer
            if (Physics.CapsuleCast(p1, p2, 0, dir, out hit, raycastPaddedDist * 3, MyLayers.knockableMask))
            {
                // if (verboseMode) Debug.Log("[ObjectManager] target is Knockable");
                inRangeKnockables.Add(hit.collider.gameObject);
            }

            // current target selected according to precedence: interactable > tools > breakable
            // ^ not really, the statement is true for each iteration, but not so overall

            // breakable layer
            if (Physics.CapsuleCast(p1, p2, 0, dir, out hit, raycastPaddedDist, MyLayers.breakableMask))
            {
                if (hit.distance < targetDist && curTool != null && (target == null || target.GetComponent <Breakable>() != null))
                {
                    target = hit.collider.gameObject;
                    //if (verboseMode) Debug.Log("[ObjectManager] target is Breakable");
                    targetDist = hit.distance;
                }
            }

            // tools layer
            // if (Physics.CapsuleCast(p1, p2, 0, dir, out hit, raycastPaddedDist, MyLayers.toolsMask))
            // {
            //     if (verboseMode) Debug.Log("[ObjectManager] tools hit something");
            //     if (verboseMode) Debug.Log(hit.collider.gameObject.name);
            //     if (hit.distance < targetDist && hit.collider.gameObject.GetComponent<Tool>() != null)
            //     {
            //         if (verboseMode) Debug.Log("[ObjectManager] target is Tool");
            //         target = hit.collider.gameObject;
            //         targetDist = hit.distance;
            //     }
            //     //Debug.Log("hit.distance < targetDist: " + (hit.distance < targetDist).ToString() + ", hit.collider.gameObject.GetComponent<Tool>() != null: " + (hit.collider.gameObject.GetComponent<Tool>() != null).ToString());
            //     if (hit.distance < targetDist && hit.collider.gameObject.GetComponent<ActiveToolController>() != null)
            //     {
            //         if (verboseMode) Debug.Log("[ObjectManager] target is Active Tool");
            //         target = hit.collider.gameObject;
            //         targetDist = hit.distance;
            //     }
            // }

            // interactable layer
            if (Physics.CapsuleCast(p1, p2, 0, dir, out hit, raycastPaddedDist, MyLayers.interactableMask))
            {
                // currently the only other interactable object is Stair
                if (hit.distance < targetDist)
                {
                    target = hit.collider.gameObject;
                    if (verboseMode)
                    {
                        Debug.Log("[ObjectManager] target is Stair");
                    }
                    targetDist = hit.distance;
                }
            }
        }

        // interact if interact button is pressed
        if (!raccoon.isStunned && Controller.GetB())
        {
            Interact();
        }


        // interact with stairs
        var stairTarget = target?.GetComponent <Stair>();

        if ((stairTarget != null))
        {
            if (verboseMode)
            {
                Debug.Log("Stair target");
            }

            // Show UI
            if (!stairTipOpen)
            {
                stairTips.Show(stairTarget.GetFloor());
                stairTipOpen = true;
            }

            var raccoon = GameManager.instance.Raccoon;
            // var stair = target.GetComponent<Stair>();
            if (stairTarget == null)
            {
                return;
            }
            // if (Controller.GetX()) Debug.Log("stairTarget: " + stairTarget.GetFloor().ToString());
            if (Controller.GetY() && stairTarget.GetFloor() != 5)
            {
                raccoon.UseStairs(true);
                stairTipOpen = false;
                stairTips.Hide();
            }
            else if (Controller.GetX() && stairTarget.GetFloor() != 1)
            {
                raccoon.UseStairs(false);
                stairTipOpen = false;
                stairTips.Hide();
            }
        }
        else if (stairTipOpen)
        {
            stairTips.Hide();
            stairTipOpen = false;
        }

        // display target health
        // if (target != null)
        // {
        //     Breakable breakableTarget = target.GetComponent<Breakable>();
        //     if (curTool != null && breakableTarget != null)
        //     {
        //         if (verboseMode) Debug.Log("[ObjectManager] target is breakable");
        //         healthBar.SetActive(true);
        //         healthBarFill.fillAmount = breakableTarget.Health / breakableTarget.totalHealth;
        //         EnableHighlight(target);
        //     }
        //     else if (breakableTarget == null)
        //     {
        //         healthBar.SetActive(false);
        //         EnableHighlight(target);
        //     }
        // }
        // else
        // {
        //     healthBar.SetActive(false);
        // }

        // Display break tip
        Breakable breakableTarget = target?.GetComponent <Breakable>();

        if (breakableTarget != null)
        {
            if (curTool != null && breakableTarget != null)
            {
                if (verboseMode)
                {
                    Debug.Log("[ObjectManager] target is breakable");
                }
                breakTip.Show();
                // healthBar.SetActive(true);
                // healthBarFill.fillAmount = breakableTarget.Health / breakableTarget.totalHealth;
                // EnableHighlight(target);
            }
        }
        else
        {
            breakTip.Hide();
        }

        // Outline in range knockables
        foreach (var k in inRangeKnockables)
        {
            EnableHighlight(k.gameObject);
        }
    }
Exemplo n.º 4
0
    // public float effectOnAttack = 10;

    private void Start()
    {
        Debug.Log("tool start");
        rb           = GetComponent <Rigidbody>();
        playerScript = GameManager.instance.Raccoon.GetComponent <RaccoonController>();
    }