Example #1
0
    //Performs interaction with gameObject based on its tag
    //Executed when player is near interactables and presses "E"
    void Interact(GameObject interactable)
    {
        if (interactable != null)
        {
            //If interactable is a torch, check that we have enough light to activate it and that it is not already lit
            //If all conditions are met, light the torch, reduce lightAmt by cost
            if (interactable.CompareTag("Torch"))
            {
                TorchScript tScript = interactable.GetComponent <TorchScript>();
                if (tScript != null)
                {
                    if (lightAmt > torchCost && !tScript.lit)
                    {
                        tScript.LightTorch();
                        lightAmt -= torchCost;
                    }
                }
            }

            else if (interactable.CompareTag("Campfire"))
            {
                CampfireScript cScript = interactable.GetComponent <CampfireScript>();
                if (cScript != null)
                {
                    if (lightAmt > torchCost && cScript.isLit == false)
                    {
                        cScript.LightCampfire();
                        lightAmt -= torchCost;
                    }
                    else if (lightAmt > torchCost && cScript.isLit == true)
                    {
                        lightAmt             = (lightAmt + cScript.campLightAmt) / 2;
                        cScript.campLightAmt = (lightAmt + cScript.campLightAmt) / 2;
                    }
                }
            }

            //If interactable is a source, give player light from the source and destroy it
            else if (interactable.CompareTag("Source"))
            {
                SourceScript sScript = interactable.GetComponent <SourceScript>();
                if (sScript != null)
                {
                    lightAmt += sScript.lightStored;
                    Destroy(interactable);
                }
            }


            else if (interactable.CompareTag("Bomb"))
            {
                Bomb bomb = interactable.GetComponent <Bomb>();
                if (bomb != null)
                {
                    bomb.Ignite();
                }
            }

            else if (interactable.CompareTag("Zipline"))
            {
                Zipline zScript = interactable.GetComponentInParent <Zipline>();
                if (zScript != null)
                {
                    if (lightAmt > ziplineCost && !zScript.isActive)
                    {
                        zScript.Activate();
                        lightAmt -= ziplineCost;
                    }
                    else
                    {
                        if (zScript.isActive)
                        {
                            Vector3 startAnchor = interactable.transform.position;
                            Vector3 endAnchor;
                            if (interactable.transform == zScript.AnchorA)
                            {
                                endAnchor = zScript.AnchorB.position;
                            }
                            else
                            {
                                endAnchor = zScript.AnchorA.position;
                            }
                            StartCoroutine(UseZipline(startAnchor, endAnchor));
                        }
                    }
                }
            }
        }
    }