Пример #1
0
    /*public int countScore(){
     *  count=0;
     *  for(int i=0;i<inventory.treasures.Count;i++){
     *      count+=inventory.treasures[i].value;
     *  }
     *  return count;
     * }*/

    void forceGrab(bool pressedA)
    {
        RaycastHit outHit;

        numitems.text = "test";
        //notice I'm using the layer mask again
        if (Physics.Raycast(rightPointerObject.transform.position, rightPointerObject.transform.up, out outHit, 100.0f, collectiblesMask))
        {
            numitems.text = "hit";
            AttachmentRule howToAttach = pressedA?AttachmentRule.KeepWorld:AttachmentRule.SnapToTarget;
            attachGameObjectToAChildGameObject(outHit.collider.gameObject, rightPointerObject.gameObject, howToAttach, howToAttach, AttachmentRule.KeepWorld, true);
            grabbed = outHit.collider.gameObject.GetComponent <CollectibleTreasure>();
            if (grabbed.name == "CubeCollectible")
            {
                rotate = true;
            }
            else
            {
                rotate = false;
            }

            //

            Vector3 scaleChange = new Vector3(-0.01f, -0.01f, -0.01f);
            presize = grabbed.transform.localScale.y;
            grabbed.transform.localScale = new Vector3(2, 2, 2);
            //
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;

        if (rightPointerObject != null)
        {
            previousPointerPos = rightPointerObject.gameObject.transform.position;
        }
        waistPosition = myCam.gameObject.transform.position - new Vector3(0, 1, 0);

        if (Input.GetKeyDown("j"))
        {
            Debug.Log("Pressed 'J' key.");
            Vector3    originPosition = myCam.gameObject.transform.position;
            Vector3    rayDirection   = myCam.gameObject.transform.forward;
            RaycastHit hit;
            if (Physics.Raycast(originPosition, rayDirection, out hit, 1))
            {
                GameObject          hitObject       = hit.collider.gameObject;
                CollectibleTreasure objectComponent = hitObject.GetComponent <CollectibleTreasure>();
                string objectName          = objectComponent.getType(); //should do a null reference check here
                CollectibleTreasure prefab = (CollectibleTreasure)Resources.Load(objectName, typeof(CollectibleTreasure));
                if (!prefab)
                {
                    Debug.Log("Prefab is null.");
                }
                addToInventory(prefab);
                Destroy(hitObject);
                updateTreasure();
                treasureItems[currentTreasureIndex].gameObject.active = true;
            }
            //triggerTrap();
        }
        else if (OVRInput.GetDown(OVRInput.RawButton.RHandTrigger))
        {
            Collider[] overlappingThings = Physics.OverlapSphere(rightPointerObject.transform.position, 0.1f, collectiblesMask);
            if (overlappingThings.Length > 0)
            {
                attachGameObjectToAChildGameObject(overlappingThings[0].gameObject, rightPointerObject, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld, true);
                //I'm not bothering to check for nullity because layer mask should ensure I only collect collectibles.
                thingIGrabbed = overlappingThings[0].gameObject.GetComponent <CollectibleTreasure>();
                if ((thingIGrabbed == trapTreasure) && !(trapTriggered))
                {
                    triggerTrap();
                }
            }
        }
        else if (OVRInput.GetUp(OVRInput.RawButton.RHandTrigger))
        {
            if (!(null == thingIGrabbed))
            {
                letGo();
            }
        }
    }
Пример #3
0
 void addToInventory(CollectibleTreasure item)
 {
     if (inventory.collectibles.ContainsKey(item))
     {
         inventory.collectibles[item] = inventory.collectibles[item] + 1;
     }
     else
     {
         inventory.collectibles.Add(item, 1);
     }
     calculateScore();
 }
Пример #4
0
 bool canPutInInventory(CollectibleTreasure item)
 {
     Collider[] overlappingWithWaistThings = Physics.OverlapSphere(waistPosition, 0.2f, collectiblesMask);
     if (overlappingWithWaistThings.Length > 0)
     {
         if (overlappingWithWaistThings[0].gameObject.GetComponent <CollectibleTreasure>() == thingIGrabbed)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
    void Update()
    {
        // if 1 is pressed, a coin is added to the treasure hunter inventory; score is updated
        if (Input.GetKeyDown("1"))
        {
            Debug.Log("Key Pressed: 1");
            if (!alreadyWon)
            {
                GameObject          coin        = GameObject.Find("Coin");
                CollectibleTreasure collectible = coin.GetComponent <CollectibleTreasure>();
                inventory.collectibles[0] = collectible;
                scoreCounter();
            }
        }

        // if 2 is pressed, a treasure chest is addded to the treasure hunter inventory; score is updated
        if (Input.GetKeyDown("2"))
        {
            Debug.Log("Key Pressed: 2");
            if (!alreadyWon)
            {
                GameObject          chest       = GameObject.Find("Treasure Chest");
                CollectibleTreasure collectible = chest.GetComponent <CollectibleTreasure>();
                inventory.collectibles[1] = collectible;
                scoreCounter();
            }
        }

        // if 3 is pressed, a diamond is added to the treasure hunter inventory; score is updated
        if (Input.GetKeyDown("3"))
        {
            Debug.Log("Key Pressed: 3");
            if (!alreadyWon)
            {
                GameObject          diamond     = GameObject.Find("Diamond");
                CollectibleTreasure collectible = diamond.GetComponent <CollectibleTreasure>();
                inventory.collectibles[2] = collectible;
                scoreCounter();
            }
        }

        // if 4 is pressed, the inventory log either turns on or off
        if (Input.GetKeyDown("4"))
        {
            Debug.Log("Key Pressed: 4");
            setInventoryMessage();
            inventoryMessageOn = !inventoryMessageOn;
            inventoryMessageObject.SetActive(inventoryMessageOn);
        }
    }
Пример #6
0
    void letGo()
    {
        detachGameObject(thingIGrabbed.gameObject, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld);
        simulatePhysics(thingIGrabbed.gameObject, (rightPointerObject.gameObject.transform.position - previousPointerPos) / Time.deltaTime, true);

        if (canPutInInventory(thingIGrabbed))
        {
            string objectName          = thingIGrabbed.getType();
            CollectibleTreasure prefab = (CollectibleTreasure)Resources.Load(objectName, typeof(CollectibleTreasure));
            if (!prefab)
            {
                Debug.Log("Prefab is null.");
            }
            addToInventory(prefab);
            CollectibleTreasure temporaryThingIGrabbed = thingIGrabbed;
            thingIGrabbed = null;
            Destroy(temporaryThingIGrabbed.gameObject);
        }

        thingIGrabbed = null;
    }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        if (rotate)
        {
            head.transform.Rotate(Random.Range(-10, 10), Random.Range(-10, 10), Random.Range(-10, 10), Space.Self);
        }
        if (!rotate)
        {
            head.transform.rotation = new Quaternion(0, 0, 0, 0);
        }
        if (Input.GetKeyDown("9")) //code for how to raycast was based off of Nick Rewkowski's VrPawn teleport code
        {
            RaycastHit outHit;
            if (Physics.Raycast(rightPointerObject.transform.position, rightPointerObject.transform.forward, out outHit, 100.0f))
            {
                if (outHit.collider.gameObject.GetComponent("CollectibleTreasure"))
                {
                    print("hit");
                    GameObject item = outHit.collider.gameObject;

                    /*string objectname = outHit.collider.gameObject.GetComponent<CollectibleTreasure>().name;
                     * bool exist = false;
                     * for(int i=0;i<inventory.treasures.Count;i++){
                     *  if(inventory.treasures.ElementAt(i).name==objectname){
                     *      inventory.amount[i]++;
                     *      exist = true;
                     *  }
                     * }
                     * if(exist==false){
                     *  inventory.treasures.Add(outHit.collider.gameObject.GetComponent<CollectibleTreasure>());
                     *  inventory.amount.Add(1);
                     * }*/
                    /*if(objectname==1){
                     *  numberofEach[0]++;
                     * } else if(objectvalue==5){
                     *  numberofEach[1]++;
                     * } else if(objectvalue==10){
                     *  numberofEach[2]++;
                     * }*/
                    Destroy(outHit.collider.gameObject);
                    int sum        = 0;
                    int totalitems = 0;
                    int spheres    = 0;
                    int cylinders  = 0;
                    int cubes      = 0;
                    int capsules   = 0;
                    for (int j = 0; j < inventory.treasures.Count; j++)
                    {
                        if (inventory.treasures[j].value == 1)
                        {
                            cylinders = inventory.amount[j];
                        }
                        if (inventory.treasures[j].value == 10)
                        {
                            cubes = inventory.amount[j];
                        }
                        if (inventory.treasures[j].value == 20)
                        {
                            capsules = inventory.amount[j];
                        }
                        if (inventory.treasures[j].value == 5)
                        {
                            spheres = inventory.amount[j];
                        }
                        sum        += inventory.treasures[j].value * inventory.amount[j];
                        totalitems += inventory.amount[j];
                    }
                    displayscore.text = totalitems + " items \n Spheres (5 ea):" + spheres + " \n Cubes (10 ea): " + cubes + "\n Capsules (20 ea): " + capsules + "\n Cylinders (1 ea): " + cylinders + "\n Total score: " + sum;
                }
            }
            print("You hit the collector button");
        }

        if (OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger))
        {
            score.text = "hit button";
            //head.transform.position = new Vector3(0,10,0);
            forceGrab(true);
        }

        if (OVRInput.GetUp(OVRInput.RawButton.RIndexTrigger))
        {
            score.text = "let go button";
            letGo();
            //head.transform.position = new Vector3(0,-1,0);
        }

        if (OVRInput.GetDown(OVRInput.RawButton.RHandTrigger))
        {
            score.text = "hit button2";
            //head.transform.position = new Vector3(0,10,0);
            forceGrab(false);
        }

        if (OVRInput.GetUp(OVRInput.RawButton.RHandTrigger))
        {
            score.text = "let go button2";
            letGo();
            //head.transform.position = new Vector3(0,-1,0);
        }

        if (OVRInput.GetDown(OVRInput.RawButton.LIndexTrigger))
        {
            score.text = "hit button3";
            //head.transform.position = new Vector3(0,10,0);
            Collider[] handgrip = Physics.OverlapSphere(leftPointerObject.transform.position, 0.1f, collectiblesMask);
            attachGameObjectToAChildGameObject(handgrip[0].gameObject, leftPointerObject.gameObject, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld, true);
            grabbed = handgrip[0].gameObject.GetComponent <CollectibleTreasure>();
            if (grabbed.name == "CubeCollectible")
            {
                rotate = true;
            }
            else if (handgrip.Length > 0)
            {
                rotate = false;
            }
            Vector3 scaleChange = new Vector3(-0.01f, -0.01f, -0.01f);
            presize = grabbed.transform.localScale.y;
        }

        if (OVRInput.GetUp(OVRInput.RawButton.LIndexTrigger))
        {
            score.text = "let go button3";
            letGo();
            //head.transform.position = new Vector3(0,-1,0);
        }

        if (OVRInput.GetDown(OVRInput.RawButton.LHandTrigger))
        {
            score.text = "Shreya Gullapalli and Ammar Puri";
        }

        if (Input.GetKeyDown("1"))
        {
            print("You hit the score button");
            //score.text = "Score = "+sum + " Ammar Puri & Shreya Gullapalli \n";
            //numitems.text = "Total Items = "+totalitems+"\n";
        }

        /*if(Input.GetKeyDown("1")){
         *  if(inventory.treasures.Contains(PointerArray[0])==false){
         *      inventory.treasures.Add(PointerArray[0]);
         *  }
         *  print("You hit 1");
         * }
         *
         * if(Input.GetKeyDown("2")){
         *  if(inventory.treasures.Contains(PointerArray[1])==false){
         *      inventory.treasures.Add(PointerArray[1]);
         *  }
         *  print("You hit 2");
         * }
         *
         * if(Input.GetKeyDown("3")){
         *  if(inventory.treasures.Contains(PointerArray[2])==false){
         *      inventory.treasures.Add(PointerArray[2]);
         *  }
         *  print("You hit 3");
         * }
         *
         * if(Input.GetKeyDown("4")){
         *  score.text="Score: " + countScore()+ "\n"+"# of obj:" + inventory.treasures.Count;
         *  print("You hit 4");
         * }
         *
         * if(inventory.treasures.Count==3){
         *  win.text="You Win! - Ammar Puri";
         * }*/
    }
Пример #8
0
 void letGo()
 {
     if (grabbed)
     {
         score.text = "first";
         waist      = center.transform.position - new Vector3(0, 1, 0);
         Collider[] overlappingThingsWithLeftHand = Physics.OverlapSphere(leftPointerObject.transform.position, 0.01f, collectiblesMask);
         Collider[] waisttrue = Physics.OverlapSphere(waist, .5f, collectiblesMask);
         score.text = "second";
         if (waisttrue.Length > 0)
         {
             score.text = "third";
             string objectname = grabbed.gameObject.GetComponent <CollectibleTreasure>().name;
             bool   exist      = false;
             score.text = "fourth";
             for (int i = 0; i < inventory.treasures.Count; i++)
             {
                 if (inventory.treasures.ElementAt(i).name == objectname)
                 {
                     inventory.amount[i]++;
                     exist = true;
                 }
             }
             if (exist == false)
             {
                 inventory.treasures.Add(grabbed.gameObject.GetComponent <CollectibleTreasure>());
                 inventory.amount.Add(1);
             }
             Destroy(grabbed.gameObject);
             int sum        = 0;
             int totalitems = 0;
             int spheres    = 0;
             int cylinders  = 0;
             int cubes      = 0;
             int capsules   = 0;
             for (int j = 0; j < inventory.treasures.Count; j++)
             {
                 if (inventory.treasures[j].value == 1)
                 {
                     cylinders = inventory.amount[j];
                 }
                 if (inventory.treasures[j].value == 10)
                 {
                     cubes = inventory.amount[j];
                 }
                 if (inventory.treasures[j].value == 20)
                 {
                     capsules = inventory.amount[j];
                 }
                 if (inventory.treasures[j].value == 5)
                 {
                     spheres = inventory.amount[j];
                 }
                 sum        += inventory.treasures[j].value * inventory.amount[j];
                 totalitems += inventory.amount[j];
             }
             displayscore.text = totalitems + " items \n Spheres (5 ea):" + spheres + " \n Cubes (10 ea): " + cubes + "\n Capsules (20 ea): " + capsules + "\n Cylinders (1 ea): " + cylinders + "\n Total score: " + sum;
         }
         if (overlappingThingsWithLeftHand.Length > 0)
         {
             if (thingOnGun)
             {
                 detachGameObject(thingOnGun, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld);
                 simulatePhysics(thingOnGun, Vector3.zero, true);
             }
             attachGameObjectToAChildGameObject(overlappingThingsWithLeftHand[0].gameObject, leftPointerObject, AttachmentRule.SnapToTarget, AttachmentRule.SnapToTarget, AttachmentRule.KeepWorld, true);
             thingOnGun = overlappingThingsWithLeftHand[0].gameObject;
             grabbed    = null;
         }
         else
         {
             Vector3 scaleChange = new Vector3(-0.01f, -0.01f, -0.01f);
             while (grabbed.transform.localScale.y < presize)
             {
                 grabbed.transform.localScale -= scaleChange;
             }
             detachGameObject(grabbed.gameObject, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld, AttachmentRule.KeepWorld);
             simulatePhysics(grabbed.gameObject, Vector3.zero, true);
             grabbed = null;
         }
         numitems.text = "let go";
     }
 }
Пример #9
0
    void Update()
    {
        // TRYING TO FIGURE OUT DISTANCE TRAVELLED
        //   float dist = Vector3.Distance(lastPosition, transform.position) ;
        // totalDistance += dist;
        // lastPosition = transform.position;


        // SETTING CURSOR TO NOT VISIBLE BECAUSE BALL SHOOTS BASED ON WHERE YOU LOOK, NOT WHERE YOUR CURSOR IS
        Cursor.visible = false;

        // HIT THE S KEY TO START (WON'T KEEP TRACK OF STEPS OR START TIME UNTIL USER HAS READ THE SIGN AND HIT S)
        if (Input.GetKeyDown(KeyCode.S))
        {
            started = true;
            startMessageObject.SetActive(false);
        }

        if (started)
        {
            // KEEPING TRACK OF FPS VALUES FOR END CALCULATION
            // double fps = 1.0/Time.deltaTime;
            // sumOfFPS = sumOfFPS + fps;
            // numOfFrames = numOfFrames + 1;

            timeElapsed += Time.deltaTime;
            numberOfLinesMessage.text = /*"Number of Steps: " + numOfSteps +*/ "Time Elapsed: " + timeElapsed.ToString("N1");

            // CHECK TO SEE IF USER HAS COLLECTED 5 OBJECTS
            if (numberOfObjectsCollected >= 5 && notDisplayedYet)
            {
                //  Debug.Log("____________Total distance travelled:" + totalDistance/10);

                // double averageFPS = sumOfFPS / numOfFrames;
                // double avgFramesPerStep = averageFPS * 5 * (0.762);


                // numOfLines counted the number of times user was hitting arrow key during a frame
                // numOfSteps = numOfLines * (1 / avgFramesPerStep);


                // Debug.Log("___________________AvgFPS" + averageFPS);
                // Debug.Log("___________________numOfFrames" + numOfFrames);
                // Debug.Log("________numOfSteps" + numOfSteps);
                // Debug.Log("___________________AvgFramePerStep " + avgFramesPerStep);
                // Debug.Log("_____________numOfLines" + numOfLines);



                // winMessage.text = "5 Objects Collected\nFinal # of Steps Taken: " + numOfLines / 15 + "\nFinal Time Elapsed: " + timeElapsed.ToString ("N1");
                //numOfSteps.ToString("N1")


                // TURN ON TWO WALLS IN GLASS ROOM
                MeshRenderer mz = wallz.GetComponent <MeshRenderer>();
                mz.enabled = true;
                MeshRenderer my = wally.GetComponent <MeshRenderer>();
                my.enabled = true;


                float totalDistanceTravelled = calc.totalDistance;
                winMessage.text = "5 Objects Collected\nTotal Distance Travelled: " + totalDistanceTravelled.ToString("N3") + " m" + "\nFinal Time Elapsed: " + timeElapsed.ToString("N1");
                winMessageObject.SetActive(true);
                notDisplayedYet = false;
                numberOfLinesObject.SetActive(false);
                scoreMessageObject.SetActive(false);
            }

            // RAYCAST TO COLLECT COLLECTIBLES
            RaycastHit hit;
            if (Physics.Raycast(oculusCam.transform.position, oculusCam.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
            {
                GameObject          hitObject = hit.collider.gameObject;
                CollectibleTreasure c         = hitObject.GetComponent <CollectibleTreasure> ();

                float distanceBetweenHunterAndSphere = (transform.position - hitObject.transform.position).magnitude;

                if (c && distanceBetweenHunterAndSphere < 10.0f)
                {
                    Debug.DrawRay(oculusCam.transform.position, oculusCam.transform.TransformDirection(Vector3.forward) * hit.distance, Color.red);
                }
                else
                {
                    Debug.DrawRay(oculusCam.transform.position, oculusCam.transform.TransformDirection(Vector3.forward) * 1000, Color.white);
                }
            }
            else
            {
                Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
            }

            // MAKES THE LINE THAT FOLLOWS THE USER AS THEY WALK
            if (Input.GetButton("Vertical"))
            {
                Instantiate(line, transform.position, transform.rotation);
                numOfLines++;



                // numOfSteps = numOfLines * spf * .2 * (1/0.4);
            }

            if (Input.GetButton("Horizontal"))
            {
                Instantiate(line, transform.position, transform.rotation);
                numOfLines++;
            }

            // HIT ENTER KEY TO COLLECT COLLECTILBE
            if (Input.GetKeyDown(KeyCode.Return))
            {
                Debug.Log("_____________Key Pressed: enter");
                // Debug.Log("Object hit: " + hit.collider.gameObject);

                // GameObject hitObject = hit.collider.gameObject;
                // CollectibleTreasure c = hitObject.GetComponent<CollectibleTreasure> ();

                // float distanceBetweenHunterAndSphere = (transform.position - hitObject.transform.position).magnitude;

                // if (c) {
                //     numberOfObjectsCollected++;
                //     Destroy (hitObject);
                // }

                foreach (CollectibleTreasure audioSphere in bag.AudioSpheres)
                {
                    if (audioSphere == null)
                    {
                        continue;
                    }
                    float distance = Vector3.Distance(transform.position, audioSphere.transform.position);
                    if (distance < 3)
                    {
                        Destroy(audioSphere.gameObject);  //might need to lower distance to maybe less than 1
                        numberOfObjectsCollected++;
                    }
                    scoreMessage.text = "Halie, Meris, Bea, LJ\n# of Objects Collected: " + numberOfObjectsCollected;
                }
            }
        }
    }