Ejemplo n.º 1
0
    protected void Update()
    {
        //test for objects that can be picked up
        Collider[] nearbyObjects = Physics.OverlapSphere(transform.position, 1, 1 << LayerMask.NameToLayer("Holdable"));
        //highlight contorller button when in range to pick up something
        if (nearbyObjects.Length > 0 && currentHeldObject == null)
        {
            LGrip.ActivateColor();
            RGrip.ActivateColor();
        }
        else
        {
            LGrip.DeActivateColor();
            RGrip.DeActivateColor();
        }
        //grab golf club / activate item
        if (SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index).GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            if (currentHeldObject == null)
            {
                PickupGolfClub();
            }
            else if (currentHeldObject != clubRigid)
            {
                currentHeldObject.GetComponent <DeathmatchItemCMDHolder>().cmd.ActivateStart();
            }
        }
        //deactivate item
        if (SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index).GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            if (currentHeldObject != null && currentHeldObject != clubRigid)
            {
                currentHeldObject.GetComponent <DeathmatchItemCMDHolder>().cmd.ActivateEnd();
            }
        }
        //release golf club
        if (!SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index).GetPress(SteamVR_Controller.ButtonMask.Trigger) && !SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index).GetPress(SteamVR_Controller.ButtonMask.Grip))
        {
            if (club != null && isHoldingClub)
            {
                clubRigid.GetComponent <ClubReturnToHand>().Throw();
                GetComponent <VelocityCalculatorNoAngles>().Apply(clubRigid.GetComponent <Rigidbody>());
                isHoldingClub     = false;
                currentHeldObject = null;
            }
        }

        //pick up/drop item
        if (SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index).GetPressDown(SteamVR_Controller.ButtonMask.Grip))
        {
            if (currentHeldObject == null) //pickup
            {
                for (int i = 0; i < nearbyObjects.Length; i++)
                {
                    currentHeldObject = nearbyObjects[i].gameObject;
                    Rigidbody r = currentHeldObject.GetComponent <Rigidbody>();
                    r.useGravity  = false;
                    r.isKinematic = true;
                    currentHeldObject.GetComponent <Collider>().enabled = false;
                    currentHeldObject.transform.parent           = transform;
                    currentHeldObject.transform.localEulerAngles = new Vector3(90, 0, 0);
                    currentHeldObject.transform.localPosition    = new Vector3(0, 0, 0.075f);
                    if (nearbyObjects[i].tag == "DeathmatchItem")
                    {
                        currentHeldObject.GetComponent <DeathmatchItemCMDHolder>().cmd.SetHoldingController(this);
                        if (PhotonNetwork.inRoom)
                        {
                            currentHeldObject.GetComponent <PhotonView>().TransferOwnership(PhotonNetwork.player);
                        }
                    }
                    break;
                }
                if (currentHeldObject == null)
                {
                    PickupGolfClub();
                }
            }
            else if (currentHeldObject != clubRigid) //let go
            {
                currentHeldObject.GetComponent <Collider>().enabled = true;
                ReleaseHeldObject();
            }
        }

        //teleport
        if (SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index).GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            TeleportCode();
        }
        else
        {
            teleporter.SetActive(false);
        }
        //menu
        if (SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index).GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            if (currentMenu != null)
            {
                currentMenu.GetComponent <MenuPanelCode>().ActivateSelector();
            }
        }

        //Open Menu
        if (SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index).GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu) && Application.loadedLevelName != "LoginScene")
        {
            if (VarsTracker.Menu == null)
            {
                if (Application.loadedLevelName == "TutorialScene")
                {
                    VarsTracker.Menu = Instantiate(Resources.Load(@"Prefabs/Menu/MenuSystemTutorial"), transform.position + transform.forward * 15, Quaternion.identity) as GameObject;
                }
                else
                {
                    VarsTracker.Menu = Instantiate(Resources.Load(@"Prefabs/Menu/MenuSystem"), transform.position + transform.forward * 15, Quaternion.identity) as GameObject;
                }
            }
            else
            {
                Destroy(VarsTracker.Menu);
                VarsTracker.Menu = null;
            }
        }
        //menu selection

        /*
         * CHANGE THIS TO ONLY ONE MENU PANEL
         * AT LEAST UNTIL I CAN FIND A BETTER IMPLEMENTATION OF UI
         *
         */
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, 100, 1 << LayerMask.NameToLayer("MenuLayer")))
        {
            menuLaser.SetActive(true);
            Trackpad.ActivateColor();
            if (currentMenu != hit.collider.gameObject)
            {
                if (currentMenu != null)
                {
                    currentMenu.GetComponent <MenuPanelCode>().DeSelected();
                }
                currentMenu = hit.collider.gameObject;
                currentMenu.GetComponent <MenuPanelCode>().Selected();
            }
            currentMenu.GetComponent <MenuPanelCode>().selector.transform.position       = hit.point;
            currentMenu.GetComponent <MenuPanelCode>().selector.transform.localPosition -= Vector3.forward;
            //MenuCode();
        }
        else
        {
            menuLaser.SetActive(false);
            Trackpad.DeActivateColor();
            if (currentMenu != null)
            {
                currentMenu.GetComponent <MenuPanelCode>().DeSelected();
            }
            currentMenu = null;
        }
    }
Ejemplo n.º 2
0
 public void PopperPopped()
 {
     myAudio.Stop();
     myAudio.PlayOneShot(Resources.Load(@"Sounds/TutorialSpeech/Complete1") as AudioClip);
     menuBtn.ActivateColor();
 }