- Home /
Question by
binaryplease · Apr 27, 2014 at 10:37 PM ·
playerfpsrespawncamerasactivation
Respawn Player / enable new camera
Hi, I'm doing quill18's tutorial on multiplayer FPS and trying to implement a respawn. I made a PLayerHealth.cs script that looks like this:
using UnityEngine;
using System.Collections;
public class Health : MonoBehaviour {
public float hitPoints = 100f;
float currentHitPoints;
//float deathTime=0;
//bool isDead= false;
SpawnSpot[] spawnSpots;
GameObject standbyCamera;
public int spawnTime = 3;
// Use this for initialization
void Start () {
spawnSpots = FindObjectsOfType<SpawnSpot>();
currentHitPoints = hitPoints;
}
void Update(){
if(Input.GetButton("Suicide")) {
// Player wants to suicide.
TakeDamage(hitPoints);
}
}
[RPC]
public void TakeDamage(float amt) {
currentHitPoints -= amt;
if(currentHitPoints <= 0) {
Die();
}
}
void Die() {
Debug.Log(gameObject.name + " died!");
Debug.Log(PhotonNetwork.player.name);
if( GetComponent<PhotonView>().instantiationId==0 ) {
Destroy(gameObject);
}
else {
if( PhotonNetwork.isMasterClient ) {
PhotonNetwork.Destroy(gameObject);
}
}
}
void Respawn() {
SpawnSpot mySpawnSpot = spawnSpots[Random.Range(0, spawnSpots.Length)];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
//((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("PlayerMovement")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("PlayerShooting")).enabled = true;
//((MonoBehaviour)myPlayerGO.GetComponent("CharacterMotor")).enabled = true;
myPlayerGO.transform.FindChild("Main Camera").gameObject.camera.enabled = true;
}
}
The player respawns and I can move it as expected ( I can see it in the Scene tab) but the camera is inactive (the Game tab is still grey).
What am i missing?
EDIT: If I activate the Camera manually in the Inspector it works perfectly.
EDIT2 nevermind, I solved it. It should have been
myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
Comment
Your answer
Follow this Question
Related Questions
Finding GameObjects within a radius? 2 Answers
Player Respawn Script 5 Answers
Player Respawn After Death 1 Answer
Question about FPS Player Script 1 Answer
In-Game Store Using Collected Coins 3 Answers