Okay so i have this piece of code. The purpose of this code is to initiate components of the player if the photonView belongs to that client. Only half of the scripts turn on and i'm pretty sure i coded it right. I have no idea why this is happening and i need some help. Another weird thing is that one of the components was working fine and all of a sudden it stopped enabling.
using UnityEngine;
using System.Collections;
public class FirstPersonNetwork : Photon.MonoBehaviour {
MouseLook cameraScript;
MouseLook cameraScript2;
Camera playerCamera;
CharacterController characterController;
CharacterMotorC characterMotor;
FPSInputControllerC inputScript;
Health playerHealth;
TeamPicker teamChanger;
SpellCaster playerCaster;
//public GameObject camera = GameObject.Find ("Main Camera");
void Awake()
{
characterController = GetComponent ();
cameraScript = GetComponent ();
cameraScript2 = GetComponentInChildren ();
characterMotor = GetComponent ();
inputScript = GetComponent ();
playerHealth = GetComponent ();
teamChanger = GetComponent();
playerCaster = GetComponent();
playerCamera = GetComponentInChildren ();
if (photonView.isMine)
{
//gameObject.tag = ("MyPlayer");
//this.camera.camera.enabled = true;
ObjectsToEnable();
}else{
//this.camera.camera.enabled = false;
ObjectsToDisable();
}
gameObject.name = gameObject.name + photonView.viewID;
}
void onPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}else{
correctPlayerPos = (Vector3) stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
private Vector3 correctPlayerPos = Vector3.zero; //We Lerp towards this
private Quaternion correctPlayerRot = Quaternion.identity; //We Lerp towards this
void update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5);
print ("your turn" + gameObject.name + photonView.isMine);
}
}
void ObjectsToDisable()
{
cameraScript.enabled = false;
cameraScript2.enabled = false;
characterMotor.enabled = false;
playerCamera.enabled = false;
characterController.enabled = true;
playerHealth.enabled = false;
teamChanger.enabled = false;
playerCaster.enabled = false;
inputScript.enabled = false;
}
void ObjectsToEnable()
{
cameraScript.enabled = true;
cameraScript2.enabled = true;
characterMotor.enabled = true;
camera.transform.parent = this.transform;
characterController.enabled = true;
inputScript.enabled = true;
playerCamera.enabled = true;
playerHealth.enabled = true;
teamChanger.enabled = true;
playerCaster.enabled = true;
}
}
I'm also getting this error but it is not affecting the game play.
NullReferenceException: Object reference not set to an instance of an object
HealthBarUI.Start () (at Assets/Scripts/Player/HealthBarUI.cs:17)
This is its script
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Health))]
public class HealthBarUI : Photon.MonoBehaviour {
EnergyBar uiBar;
Health healthCurrent = null;
GameObject player;
Player playerScript;
void Start()
{
player = GameObject.FindGameObjectWithTag ("MyPlayer");
uiBar = GetComponent();
healthCurrent = player.GetComponent();
playerScript = player.GetComponent();
uiBar.valueCurrent = healthCurrent.health;
uiBar.valueMax = healthCurrent.maxHealth;
}
void Update()
{
if (healthCurrent == null)
{
Debug.Log("You have no Health! or healthCurrent = null");
}else{
if (healthCurrent.health <= 0)
{
healthCurrent.health = 0;
playerScript.RespawnPlayer();
}
}
}
}
Can any one shed some light? I think that that error is not allowing my scripts to update but it doesn't stop the game from running so that makes no sense.
↧