// Open the portal public void OpenPortal(Dimension destination, Dimension origin, FloatHolder knifeFloat) { if (!initialised) { InitPortal(knifeFloat); } m_destination = destination; m_origin = origin; // Change the portal to the right layer if (m_origin == Dimension.Default) { gameObject.layer = LayerMask.NameToLayer("Default"); } else { gameObject.layer = LayerMask.NameToLayer("Default_" + m_origin.ToString()); } // Play the correct audio m_effectSource.PlayOneShot(m_effectAudio); m_player.isCreatingPortal = true; m_windSource.clip = m_windAudio; m_windSource.loop = true; m_windSource.Play(); m_dimensionSource.clip = m_dimensionAudio[(int)destination]; m_dimensionSource.loop = true; m_dimensionSource.Play(); StartCoroutine(OpenPortalCoroutine()); }
// Initialise up the player public void PlayerInit() { // Find and assign various references m_transform = GetComponent <Transform>(); cameraAnchor = m_transform.Find("CameraAnchor"); // Get the number of dimension cameras needed m_numberOfDimensions = Dimension.GetNames(typeof(Dimension)).Length; // Create the cameras needed for each dimension CreatePlayerCameras(); // Get references to various objects m_body = GetComponent <Rigidbody>(); m_col = m_transform.Find("Collider").GetComponent <CapsuleCollider>(); m_groundCheck = m_transform.Find("GroundCheck"); m_sceneLoader = GameObject.Find("GM").GetComponent <DimensionSceneLoader>(); m_knife = cameraAnchor.Find("Knife"); m_knifeAnim = m_knife.GetComponent <Animator>(); m_knifeFloat = m_knife.GetComponent <FloatHolder>(); // For each dimension, add a background soundtrack m_audioSources = new AudioSource[m_numberOfDimensions]; for (int i = 0; i < m_numberOfDimensions; i++) { m_audioSources[i] = gameObject.AddComponent <AudioSource>(); m_audioSources[i].loop = true; m_audioSources[i].clip = m_dimensionAudio[i]; m_audioSources[i].volume = 0; m_audioSources[i].Play(); } // Get the controls and debug ui m_controlsText = GameObject.Find("ControlsText").GetComponent <Text>(); m_debugText = GameObject.Find("DebugText").GetComponent <Text>(); // Prevent the player's rigidbody from rotating m_body.freezeRotation = true; // Lock the cursor to the center of the screen and hide it Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; // Create the render textures used for dimension previews CreateRenderTextures(); // Switch to the normal dimension SwitchDimensionImmediate(Dimension.Default, Dimension.Dark); // Start the FPS counter StartCoroutine(FpsCoroutine()); // Declare that the player is all set up and ready to go! isInitialized = true; }
private AudioSource m_windSource; // The audio source for the wind sound // Set up the portal private void InitPortal(FloatHolder knifeFloat) { // Get various objects m_transform = GetComponent <Transform>(); m_renderer = GetComponent <Renderer>(); m_player = GameObject.Find("Player").GetComponent <PlayerController>(); m_effectSource = gameObject.AddComponent <AudioSource>(); m_dimensionSource = gameObject.AddComponent <AudioSource>(); m_windSource = gameObject.AddComponent <AudioSource>(); m_knifeFloat = knifeFloat; startScale = m_transform.localScale; endScale = new Vector3(30f, 30f, 1f); m_state = PortalState.Opening; // The portal is all set up initialised = true; }