Making a MultiPlayer Fps in Unity E15: error

Updated on August 24, 2018 in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
5 on August 19, 2018

My Explosion Prefab Keeps Disappearing from the Player Script Fill in the Inspector, I don’t know what’s causing it, when i Press Play then click on the player in Hierarchy there is no explosion in the Death Effect Slot of the player script…… Why it keeps Disappearing and Saying None Game Object on the Player Script in the Inspector, After you’ve already Dragged it in?…..Help Please 

 

 
REPLY

  • Liked by
Reply
0 on August 20, 2018

Could you show us the script?

Are you setting it to null in the start or awake method?

 

  • Liked by
Reply
Cancel
1 on August 20, 2018

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class Player : NetworkBehaviour {

[SyncVar]
private bool _isDead = false;
public bool isDead
{
get { return _isDead; }
protected set { _isDead = value; }
}

[SerializeField]
private int maxHealth = 100;

[SyncVar]
private int currentHealth;

[SerializeField]
private Behaviour[] disableOnDeath;
private bool[] wasEnabled;

[SerializeField]
private GameObject[] disableGameObjectsOnDeath;

[SerializeField]
private GameObject deathEffect;

public void Setup ()
{
wasEnabled = new bool[disableOnDeath.Length];
for (int i = 0; i < wasEnabled.Length; i++)
{
wasEnabled[i] = disableOnDeath[i].enabled;
}

SetDefaults();
}

void Update()
{
if (!isLocalPlayer)
return;

if (Input.GetKeyDown(KeyCode.K))
{
RpcTakeDamage(99999);
}
}

[ClientRpc]
public void RpcTakeDamage (int _amount)
{
if (isDead)
return;

currentHealth -= _amount;

Debug.Log(transform.name + ” now has ” + currentHealth + “health”);

if (currentHealth <= 0)
{
Die();
}
}

private void Die()
{
isDead = true;

//Disable components
for (int i = 0; i < disableOnDeath.Length; i++)
{
disableOnDeath[i].enabled = false;
}

//Diable GameObjects
for (int i = 0; i < disableGameObjectsOnDeath.Length; i++)
{
disableGameObjectsOnDeath[i].SetActive(false);
}

//Disable the collider
Collider _col = GetComponent<Collider>();
if (_col != null)
_col.enabled = false;

//Spawn a death effect
GameObject _gfxIns = (GameObject)Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(_gfxIns, 3f);

Debug.Log(transform.name + ” is DEAD!”);

StartCoroutine(Respawn());
}

private IEnumerator Respawn ()
{
yield return new WaitForSeconds(GameManager.instance.matchSettings.respawnTime);

SetDefaults();
Transform _spawnPoint = NetworkManager.singleton.GetStartPosition();
transform.position = _spawnPoint.position;
transform.rotation = _spawnPoint.rotation;

Debug.Log(transform.name + ” respawned.”);
}

public void SetDefaults ()
{
isDead = false;

currentHealth = maxHealth;

//Enable the components
for (int i = 0; i < disableOnDeath.Length; i++)
{
disableOnDeath[i].enabled = wasEnabled[i];
}

//Enable the gameobjects
for (int i = 0; i < disableGameObjectsOnDeath.Length; i++)
{
disableGameObjectsOnDeath[i].SetActive(true);
}

//Enable the collider
Collider _col = GetComponent<Collider>();
if (_col != null)
_col.enabled = true;
}

}

on August 21, 2018

Hey, your code is correct.

 

Maybe you’re trying to set the deathEffect at the inspector at runtime ?

 

Show more replies
  • Liked by
Reply
Cancel
0 on August 24, 2018

I’ve fixed it, I was dragging the Death Effect into the 

prefab settings in the inspector, when i should be dragging it to the Original Player that i made the prefab from 

  • Liked by
Reply
Cancel
0 on August 24, 2018

Now that I’ve fixed that,  I now come up on another Problem.

During Writing the Host Game Script After Writing the Debug.Log then underneath that line where it says networkManager.matchMaker.CreateMatch,      when i wrote the word CreateMatch, it just gives me a red underline for CreateMatch. 

  • Liked by
Reply
Cancel