Пример #1
0
 IEnumerator GiveLight(CampfireScript campfire)
 {
     while (Input.GetKey(KeyCode.E) && lightAmt >= 1.0f && nearbyInteractables.Contains(campfire.gameObject))
     {
         lightAmt -= campfire.campDrainSpeed * Time.deltaTime;
         campfire.campLightAmt += campfire.campDrainSpeed * Time.deltaTime;
         yield return(null);
     }
 }
Пример #2
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));
                        }
                    }
                }
            }
        }
    }
Пример #3
0
    void Update()
    {
        CollectablesText.text = (collectiblesCollected + "/6");

        // Shooting (Charlie)
        PointAtMouse();

        if (Input.GetMouseButtonDown(0))
        {
            throwLight(thrownLightPrefab);
            lightAmt -= BudCost;
        }

        if (Input.GetMouseButtonDown(1))
        {
            throwLight(thrownFlarePrefab);
            lightAmt -= FlareCost;
        }


        //Reduce light every second and check for death
        if (lightAmt > 0)
        {
            lightAmt -= lightLostPerSecond * Time.deltaTime;
        }
        else
        {
            Death();
        }

        //Move visualization towards actual light amount based on speed
        lightAmtVisualized += (lightAmt - lightAmtVisualized) * lightAmtVSpeed * Time.deltaTime;

        //Set detection and vision mask radiuses
        detectionRadius          = lightAmtVisualized * lightDetectionMulti;
        visionRadius             = lightAmtVisualized * lightVisionMulti;
        detectionMask.localScale = new Vector3(detectionRadius, detectionRadius, 1);
        visionMask.localScale    = new Vector3(visionRadius, visionRadius, 1);

        //If in grace period, disable the player's detection collider so enemies will chase the dropped light
        if (graceTimer <= 0)
        {
            detectionCollider.enabled = true;
        }
        else
        {
            graceTimer -= Time.deltaTime;
            detectionCollider.enabled = false;
        }

        //Handles interactions
        //If there is at least 1 object in the nearbyInteractables list, show indicator and allow player to press E to interact
        if (nearbyInteractables.Count > 0)
        {
            interactText.SetActive(true);
            if (Input.GetKeyDown(KeyCode.E))
            {
                Interact(GetNearestInteractable());
            }
        }
        else
        {
            interactText.SetActive(false);
        }

        //If nearest interactable is the campfire and E isn't pressed, drain light from the campfire
        GameObject nearestInteractable = GetNearestInteractable();

        if (nearestInteractable != null)
        {
            if (nearestInteractable.CompareTag("Campfire"))
            {
                CampfireScript campfire = GetNearestInteractable().GetComponent <CampfireScript>();
                if (campfire != null)
                {
                    if (campfire.campLightAmt > 0 && !Input.GetKey(KeyCode.E))
                    {
                        lightAmt += campfire.campDrainSpeed * Time.deltaTime;
                        campfire.campLightAmt -= campfire.campDrainSpeed * Time.deltaTime;
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }

        if (Input.GetKeyDown(KeyCode.Comma))
        {
            lightAmt -= 1.0f;
        }
        if (Input.GetKeyDown(KeyCode.Period))
        {
            lightAmt += 1.0f;
        }

        if (collectiblesCollected >= collectiblesGoal)
        {
            Win();
        }
    }