private void Start()
    {
        //add our levelwasloaded event to activeSceneChanged so we can update our transform
        SceneManager.sceneLoaded += OnSceneLoaded;

        //get the startingpos info
        PlayerStartingPos startingPos = GameObject.FindObjectOfType <PlayerStartingPos>();

        //update our position, rotation and scale
        transform.localPosition    = startingPos.VrPos;
        transform.localEulerAngles = startingPos.VrRot;
        transform.localScale       = startingPos.VrScale;
    }
Beispiel #2
0
    //run on the first frame the object is active
    private void Start()
    {
        Player = GetComponent <BaseNonVRPlayer>();

        //make ourselves a cool colour
        int     hue   = Random.Range(0, 767);
        Color32 color = new Color32(
            (byte)Mathf.Clamp(hue, 0, 255),
            (byte)(Mathf.Clamp(hue, 256, 511) - 256),
            (byte)(Mathf.Clamp(hue, 512, 767) - 256),
            (byte)255);

        GetComponent <MeshRenderer>().material = new Material(GetComponent <MeshRenderer>().material);
        GetComponent <MeshRenderer>().material.SetColor("_Color", color);

        //get the player's rigidbody
        playerRB = playerMainObject.GetComponent <Rigidbody>();

        //don't run if this instance isn't locally owned
        if (!Player.LocalOwned)
        {
            //make the rigidbody kinematic if this isn't the local instance
            playerRB.isKinematic = true;
            //disable the camera too
            playerCamera.SetActive(false);
            return;
        }

        //lock and hide the mouse
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible   = false;

        //get the startingpos info
        PlayerStartingPos startingPos = GameObject.FindObjectOfType <PlayerStartingPos>();

        if (startingPos)
        {
            //update our position, rotation and scale
            transform.localPosition    = startingPos.NonVRPos;
            transform.localEulerAngles = startingPos.NonVRRot;
            transform.localScale       = startingPos.NonVRScale;
        }

        //if there's ui to instantiate, instantiate it
        if (UIifLocal)
        {
            Instantiate(UIifLocal);
        }
    }
    private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        //get the scene info object
        List <GameObject> sceneObjects = new List <GameObject>();

        scene.GetRootGameObjects(sceneObjects);
        GameObject sceneInfo = sceneObjects[0];
        //get the startingpos info
        PlayerStartingPos startingPos = sceneInfo.GetComponent <PlayerStartingPos>();

        //update our position, rotation and scale
        transform.localPosition    = startingPos.VrPos;
        transform.localEulerAngles = startingPos.VrRot;
        transform.localScale       = startingPos.VrScale;
    }