I’m making a short transition into the start of the game, and I want to disable the script controlling the player and camera movement.
Here’s what I got so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class GameStart : MonoBehaviour {
public Camera cam;
public AudioSource audioSource;
public AudioClip turnOn;
public AudioClip beep;
FirstPersonController player;
public IEnumerator Start () {
player.enabled = false;
audioSource.PlayOneShot (beep);
yield return new WaitForSeconds (1);
audioSource.PlayOneShot (turnOn);
Destroy (cam);
player.enabled = true;
}
Basically I have a plane with a black material in front of the player, which is a child of the camera I’m disabling.
I have everything setup correctly (all the correct objects put into the inspector fields).
As soon as the game starts, it’s supposed to disable the movement script, play a sound, wait one second, play another sound, remove the camera along with its child so the player can see, and enable the script so they can move.
I tried first calling a GameObject for the player, then doing “GetComponent” to get the script, but then the “enabled” both turn red. And I don’t think I need to specifically state the script as a component for this to work, as technically it should just disable any and all instances of that script.
I’m currently not getting any errors or anything like that, but it just doesn’t seem to be working. If I remove the “enabled” lines, the sounds play and the camera is removed. So it’s definitely the enabling and disabling that’s the problem.
Also, I don’t know if just removing the camera, removes the children. So what I got currently, is a “Black Screen” layer, which only that camera can see. So if I remove the camera, the plane isn’t being rendered. But I just wanna make sure it’s removed, just incase it causes some raycast-type malfunctions in the future or something.