Created
April 7, 2017 04:30
-
-
Save sam-keene/3a47bbd47804202ab21e1bb35d1096c8 to your computer and use it in GitHub Desktop.
Part of a Medium tutorial on building a multiplayer game in Daydream VR and Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerController : MonoBehaviour { | |
public GameObject gvrControllerPointer; | |
public GameObject head; | |
public GameObject otherPlayersController; | |
public GameObject playerCamera; | |
// Used to check if is this user's player or an external player | |
public bool isControllable; | |
// Use this for initialization | |
void Start () { | |
if (isControllable) { | |
TeleportEvent teleportEvent = GameObject.Find("TeleportController").GetComponent<SDKBoyTeleportController>().teleportEvent; | |
teleportEvent.AddListener (HandleTeleportEvent); | |
playerCamera.SetActive (true); | |
gvrControllerPointer.SetActive (true); | |
head.SetActive (false); | |
otherPlayersController.SetActive (false); | |
} else { | |
playerCamera.SetActive (false); | |
gvrControllerPointer.SetActive (false); | |
} | |
} | |
// Handle Telelport UnityEvent | |
private void HandleTeleportEvent (Vector3 worldPos){ | |
gameObject.transform.position = new Vector3(worldPos.x, gameObject.transform.position.y, worldPos.z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment