示例#1
0
    // Update is called once per frame
    void Update()
    {
        throwCorrected = Debouncer.Debounce("Throw", throwCorrected);
        if (isPickedUp)
        {
            transform.parent = null;
            GameObject playerHead = GameObject.Find("LitCamera");

            RaycastHit info;
            Physics.Raycast(playerHead.transform.position, playerHead.transform.forward, out info, 2, 1 << LayerMask.NameToLayer("Map"));
            transform.position = (playerHead.transform.position + (playerHead.transform.forward.normalized * (info.collider != null ? info.distance - 0.1f : 2)));

            GetComponent<Rigidbody>().velocity = new Vector3();

            if (throwCorrected.IsPressed())
            {
                isPickedUp = false;
            }

            if (Time.time - lastTimeNotHeld > 20 && ItemInventory.objects.Count == 0)
            {
                HeadsUpDisplayController.Instance.DrawText("You can store multiple items in your inventory", 0, 0.5f, Color.yellow, 0.05f);
                HeadsUpDisplayController.Instance.DrawText("To access your inventory look down to your left", 0, 0.3f, Color.yellow, 0.05f);
            }
        }
        else
        {
            lastTimeNotHeld = Time.time;
        }

        if (ItemInventory.isInBag(this) && !ItemInventory.isOpen)
        {
            transform.position = (new Vector3(0, -100.0f, 0));
        }
    }
示例#2
0
 void Update()
 {
     pressACorrected = Debouncer.Debounce("Interact", pressACorrected);
     if (waitStarted == 0)
     {
         if (pressACorrected.IsPressed())
         {
             waitStarted = Time.time;
             GetComponent<Renderer>().material.mainTexture = two;
         }
     }
     else
     {
         if (waitStarted < Time.time - waitTime)
         {
             Application.LoadLevel(1);
         }
     }
 }
示例#3
0
文件: HeadLamp.cs 项目: JonECG/Spoopy
    void Update()
    {
        bool tapped = false;
        //if( !Application.isEditor )
        {
            Ovr.Vector3f ang = OVRManager.capiHmd.GetTrackingState().HeadPose.AngularAcceleration;
            deltaAccel = Mathf.Abs(ang.x) + Mathf.Abs(ang.y) + Mathf.Abs(ang.z);

            tapRest -= Time.deltaTime;

            if (deltaAccel > tapThreshold && tapRest <= 0)
            {
                Debug.Log("Tap");
                deltaAccel = 0;
                tapRest = tapDelay;
                tapped = true;
            }
        }

        headLampToggleCorrected = Debouncer.Debounce("HeadLampToggle", headLampToggleCorrected);
        headLampChargeCorrected = Debouncer.Debounce("HeadLampRecharge", headLampChargeCorrected);

        if (currentBatteryLife > 0)
        {
            lastTimeWithCharge = Time.time;
        }

        if (Time.time - lastTimeWithCharge > delayForPromptingRecharge)
        {
            HeadsUpDisplayController.Instance.DrawText("Press (X) Several Times to Recharge Your Headlamp", 0, 0.5f, Color.yellow, 0.05f);
            HeadsUpDisplayController.Instance.DrawText("Then Press (Y) to Turn Your Headlamp On", 0, 0.3f, Color.yellow, 0.05f);
        }

        if (headLampToggleCorrected.IsPressed())
        {
            if( SoundManagerController.Instance != null )
                SoundManagerController.Instance.PlaySoundAt(isTurnedOn ? clickOff : (currentBatteryLife > 0) ? clickOn : clickDead, transform.position, "PlayerMadeSound");
            if (currentBatteryLife > 0)
                isTurnedOn = !isTurnedOn;
        }

        if (headLampChargeCorrected.IsPressed() || tapped)
        {
            currentBatteryLife = Mathf.Min(batteryLifeInSeconds, currentBatteryLife + batteryLifeInSeconds / numberOfShakesToCharge);
            if (SoundManagerController.Instance != null)
                SoundManagerController.Instance.PlaySoundAt((currentBatteryLife == batteryLifeInSeconds) ? rechargeFull : recharge, transform.position, "PlayerMadeSound");
        }

        if (isTurnedOn)
        {
            currentBatteryLife -= Time.deltaTime;

            if (currentBatteryLife <= 0)
            {
                currentBatteryLife = 0;
                isTurnedOn = false;
                if (SoundManagerController.Instance != null)
                    SoundManagerController.Instance.PlaySoundAt(clickOff, transform.position, "PlayerMadeSound");
            }
        }

        if (isTurnedOn)
        {
            float weakenedPower = (currentBatteryLife > weakenTime) ? 1 : currentBatteryLife / weakenTime;
            GetComponent<Light>().enabled = Random.value <= weakenedPower;
            GetComponent<Light>().intensity = weakenedPower * maxIntensity;
            glow.intensity = weakenedPower * maxGlow;
        }
        else
        {
            GetComponent<Light>().enabled = false;
        }

        glow.enabled = GetComponent<Light>().enabled;
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        pickupCorrected = Debouncer.Debounce("PickUp", pickupCorrected);
        openInventory = Debouncer.Debounce("OpenInventory", openInventory);
        storeCorrected = Debouncer.Debounce("Store", storeCorrected);
        interactCorrected = Debouncer.Debounce("Interact", interactCorrected);

        List<ItemInteraction> items = ItemInteraction.allItems;
        List<DoorKnob> doors = DoorKnob.allDoors;

        float angle = 360.0f;

        GameObject playerHead = GameObject.Find("LitCamera");

        angle = Vector3.Angle(playerHead.transform.forward, inventory.transform.position - playerHead.transform.position);

        int selection = -1;
        for (int i = 0; i < items.Count && angle>0; i++)
        {
            if (items[i] != null)
            {
                if (Vector3.Distance(playerHead.transform.position, items[i].transform.position) < 3 && Vector3.Angle(playerHead.transform.forward, items[i].transform.position - playerHead.transform.position) < angle)
                {
                    angle = Vector3.Angle(playerHead.transform.forward, items[i].transform.position - playerHead.transform.position);
                    selection = i;
                }

                if (items[i].isPickedUp)
                {
                    angle = 0;
                    selection = i;
                }
            }
        }

        for (int i = 0; i < doors.Count && angle > 0; i++)
        {
            if (doors[i] != null)
            {
                if (Vector3.Distance(playerHead.transform.position, doors[i].transform.position) < 3 && Vector3.Angle(playerHead.transform.forward, doors[i].transform.position - playerHead.transform.position) < angle)
                {
                    angle = Vector3.Angle(playerHead.transform.forward, doors[i].transform.position - playerHead.transform.position);
                    selection = i + items.Count;
                }
                if (doors[i].isGrabbed)
                {
                    angle = 0;
                    selection = i + items.Count;
                }
            }
        }

        if (angle < 25)
        {
            if (selection >= 0 && selection < items.Count)
            {
                //Picking up
                if (pickupCorrected.IsPressed() && !items[selection].isPickedUp)
                {
                    TakeItemTriggerer t = items[selection].GetComponent<TakeItemTriggerer>();
                    if( t != null )
                        t.Take();

                    if (items[selection].isTakeable)
                    {
                        Destroy(items[selection].gameObject);
                    }
                    else
                    {
                        items[selection].isPickedUp = true;
                        if (ItemInventory.isInBag(items[selection]))
                        {
                            ItemInventory.removeItem(items[selection]);
                            ItemInventory.isOpen = false;
                        }
                        if (ItemInventory.isOpen)
                            ItemInventory.isOpen = false;
                    }
                }
                //Dropping/storing
                else if (items[selection].isPickedUp && Vector3.Distance(items[selection].transform.position, inventory.transform.position) < 0.5)
                {
                    if (pickupCorrected.IsPressed())
                    {
                        items[selection].isPickedUp = false;
                    }

                    HeadsUpDisplayController.Instance.DrawText("Store Item", 0, 0, Color.blue);
                    if (storeCorrected.IsPressed())
                    {
                        items[selection].isPickedUp = false;
                        ItemInventory.storeItem(items[selection]);
                    }
                }
                //Just dropping
                else if (pickupCorrected.IsPressed() && items[selection].isPickedUp)
                {
                    items[selection].isPickedUp = false;
                }
                //Prompt for picking up
                else if (!items[selection].isPickedUp)
                {
                    HeadsUpDisplayController.Instance.DrawText(items[selection].info, 0, -0.1f, Color.blue);
                    HeadsUpDisplayController.Instance.DrawText("Press (A) to " + (items[selection].isTakeable ? "Take" : "Pick up"), 0, 0.1f, Color.blue);
                }
            }
            else if (selection >= (items.Count))
            {
                if (interactCorrected.IsPressed() && !doors[selection - items.Count].isGrabbed)
                {
                    doors[selection - items.Count].isGrabbed = true;
                    doors[selection - items.Count].door.RequestUnlatch();
                    doors[selection - items.Count].grabbedDistance = Vector3.Distance(doors[selection - items.Count].transform.position, playerHead.transform.position);
                }
                else if ((interactCorrected.IsReleased() || (Vector3.Distance(playerHead.transform.position, doors[selection - items.Count].transform.position) > 3)) && doors[selection - items.Count].isGrabbed)
                {
                    doors[selection - items.Count].isGrabbed = false;
                    doors[selection - items.Count].door.RequestLatch();
                }

                if (doors[selection - items.Count].door.Locked)
                    HeadsUpDisplayController.Instance.DrawText("Locked -- Needs " + doors[selection - items.Count].door.adjColor.Name.ToUpper() + " Key", 0, 0, doors[selection - items.Count].door.adjColor.Color);
                else if (doors[selection - items.Count].isGrabbed)
                    HeadsUpDisplayController.Instance.DrawText("Turn to Move the Door",0,0,Color.blue);
                else if (!doors[selection - items.Count].isGrabbed)
                    HeadsUpDisplayController.Instance.DrawText("Hold (A) to Grab Handle",0,0,Color.blue);
                //Add more else ifs for more heads up displays if needed, I'm going to bed
            }
            else
            {
                //Inventory
                if (openInventory.IsPressed() && !ItemInventory.isOpen)
                {
                    ItemInventory.isOpen = true;
                }
                else if (openInventory.IsPressed() && ItemInventory.isOpen)
                {
                    ItemInventory.isOpen = false;
                }
                else if (!ItemInventory.isOpen && ItemInventory.objects.Count > 0)
                    HeadsUpDisplayController.Instance.DrawText("Press (A) to Open Inventory", 0, 0, Color.blue);
                else if (ItemInventory.isOpen)
                    HeadsUpDisplayController.Instance.DrawText("Press (A) to Close Inventory", 0, 0, Color.blue);
            }
        }
    }