My script got more than 1500 line, destroy(this) destroy the script of player who aren’t suppose to be controlled on client side, it works well at this moment
Here the codes:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class PlayerController_Net : NetworkBehaviour
{
public bool canWallJump = true;
public int currentHealth;
public Texture viseurTexture;
public Texture healthTexture;
public float hpbarlenght;
public Texture fondTexturebar;
public Texture ammoBarTexture;
public float ammobarlenght;
public float ammobarpercent;
public Texture manaBarTexture;
public float manabarlenght;
public float manabarpercent;
public GameObject ToPManager;
public bool GradinCantAttack = false;
public float timeTeam = 15;
public bool beforeRoundTeam = true;
[SyncVar] public bool DontAttack = false;
public enum Selection { none, minato, saitama, goku, war };
public Selection currentSelect;
// public GameObject MinatoButton;
// public bool minato;
public GameObject playerselected;
public GameObject MinatoPlayer;
// public GameObject SaitamaButton;
// public bool Saitama;
public GameObject SaitamaPlayer;
// public GameObject GokuButton;
// public bool Goku;
public GameObject GokuPlayer;
// public GameObject WarButton;
// public bool War;
public GameObject WarPlayer;
public GameObject LobbyFrom;
public bool airDodgeFall;
public int team;
bool heavyStuckColliderBool = false;
bool runDodgeBool = false;
bool chargeStuck = false;
bool dodgeJumpGroundBool = false;
bool dodgeJumpCancelCorou = false;
bool dodgeJumpCanceled = false;
bool dodgeJumpCancel = false;
bool heavyWaitBool = false;
bool WarHeavyStun = false;
bool canHeavy = true;
bool HeavyStuckBool = false;
bool canFoot = false;
bool afterHoldHeavy = false;
float startTime = 0f;
float holdTime = 0.3f;
public AudioSource Slash;
public Image imageCooldownAbility1;
public Image imageCooldownAbility2;
public Image imageCooldownAbility3;
public Image imageCooldownAbility4;
public Image imageCooldownAbility5;
bool isCoolDown1;
bool isCoolDown2;
bool isCoolDown3;
bool isCoolDown4;
bool isCoolDown5;
public bool canGreyFire = true;
public bool canGaruru = true;
public bool canGaia = true;
float SpPerSecond = 3f;
private float regenSp;
float ammoPerSecond = 5f;
private float regenAmmo;
public RectTransform ammobar;
[SyncVar(hook = "OnChangeAmmo")] public int currentAmmo = maxAmmo;
public const int maxAmmo = 100;
public RectTransform spbar;
[SyncVar(hook = "OnChangeSp")] public int currentSp = maxSp;
public const int maxSp = 100;
bool one_z = false;
bool timer_running;
float timer_for_double_z;
float delay = 0.5f;
float BraveSpeed = 50;
float moveSpeed = 8;
float jumpForce = 20;
float dodgeSpeed = 20;
float fallForce = -10;
public CharacterController controller;
float gravityScale = 7;
public Animator anim;
public Transform pivot;
float rotateSpeed = 30;
float runSpeed = 15;
float attackSpeed = 10;
float omegaSpeed = 50;
float clawSpeed = 30;
float clawSpeed2 = 180;
float wallSpeed = 30;
public GameObject Camera1;
public GameObject OmeCamera;
public Camera Camera2;
public Camera OmeCamera2;
public Camera cam;
public int CamMode;
public AudioSource DramonKillerSound;
public AudioSource SwordSound;
Rigidbody Rigid;
bool action = false;
float cooldowntime = 50;
float cooldowntime2 = 40;
float cooldowntime3 = 20;
float cooldowntime4 = 15;
float cooldowntime5 = 1;
float cooldowntime6 = 1;
float cooldowntime7 = 0.3f;
float cooldowntime9 = 5;
float cooldowntime10 = 40;
float cooldowntime12 = 0.5f;
float cooldowntime13 = 1f;
float cooldowntime14 = 2f;
float nextFireTime = 0;
float nextFireTime2 = 0;
float nextFireTime3 = 0;
float nextFireTime4 = 0;
float nextFireTime5 = 0;
float nextFireTime6 = 0;
float nextFireTime7 = 0;
float nextFireTime8 = 0;
float nextFireTime9 = 0;
float nextFireTime10 = 0;
float nextFireTime12 = 0;
float nextFireTime13 = 0;
float nextFireTime14 = 0;
bool charge;
bool Shot;
public AudioSource Impact2;
public Transform target;
public bool canAttack = true;
bool turning = false;
bool pushed = false;
bool WallHited = false;
bool Down1 = false;
bool Down2 = false;
bool downWallFall = false;
bool DownWall = false;
bool Down3 = false;
bool DashedUltra = false;
public bool canDodge = false;
private float knockBackCounter;
public GameObject AudioListenerCamera;
private Vector3 moveDirection;
public GameObject playerModel;
public Transform cameraTransform;
public Transform cameraTransform2;
void Start()
{ if (!isLocalPlayer)
{
AudioListenerCamera.SetActive(false);
Camera2.enabled = false;
OmeCamera2.enabled = false;
Destroy(this);
return;
}
controller = GetComponent<CharacterController>();
ToPManager = GameObject.FindWithTag("ToPManager");
}
There’s way more after
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
public class MyLobby : NetworkManager {
public bool canDontAttackLaunch = false;
public float TimeButtonJoin = 0f;
public bool endBeforeTime = false;
public bool newRound = false;
public bool DontAttackManager = true;
public bool DontStartRound = true;
public bool StartRoundBool = true;
public GameObject ToPManager;
public GameObject WarpToGame;
public float timeEndRound = 300f;
public bool EndRoundBool = false;
public float timeStartRound = 15f;
public float timeStartRoundAttack = 15f;
public bool StartAttackBool = false;
public GameObject SpawnEnter;
public GameObject LobbyOption;
public GameObject TitleScreen;
private bool TitleBool;
public enum Selection { none, minato, saitama, goku, war };
public Selection currentSelect;
private float nextRefreshTime = 2f;
// public GameObject MinatoButton;
// public bool minato;
public GameObject playerselected;
public GameObject MinatoPlayer;
// public GameObject SaitamaButton;
// public bool Saitama;
public GameObject SaitamaPlayer;
// public GameObject GokuButton;
// public bool Goku;
public GameObject GokuPlayer;
// public GameObject WarButton;
// public bool War;
public GameObject WarPlayer;
public GameObject Player;
public void Start()
{
RefreshMatches();
}
public void StartHosting()
{
StartMatchMaker();
matchMaker.CreateMatch("Room" + TimeButtonJoin, 4, true, "", "", "", 0, 0, OnMatchCreated);
DontStartRound = false;
LobbyOption.SetActive(false);
canDontAttackLaunch = true;
}
private void OnMatchCreated(bool success, string extendedInfo, MatchInfo responseData)
{
base.StartHost(responseData);
RefreshMatches();
}
public void Update()
{
TimeButtonJoin += Time.deltaTime;
ToPManager = GameObject.FindWithTag("ToPManager");
WarpToGame = GameObject.FindWithTag("WarpToGame");
if (DontAttackManager == true && canDontAttackLaunch == true)
{
ToPManager.GetComponent<ToPManager>().CmdDontAttack();
}
if (EndRoundBool == false)
{
timeEndRound = 300;
}
else
{
timeEndRound -= Time.deltaTime;
ToPManager.GetComponent<ToPManager>().Timer3();
}
if (StartAttackBool == false)
{
timeStartRoundAttack = 15;
}
else
{
timeStartRoundAttack -= Time.deltaTime;
ToPManager.GetComponent<ToPManager>().Timer2();
}
if (DontStartRound == true)
{
timeStartRound = 15;
}
else
{
ToPManager.GetComponent<ToPManager>().Timer1();
ToPManager.GetComponent<ToPManager>().CmdTeamSelectMoment();
timeStartRound -= Time.deltaTime;
}
if (timeStartRound < 0 & StartRoundBool == true)
{
ToPManager.GetComponent<ToPManager>().CmdStartRound();
WarpToGame.GetComponent<WarpToGame>().canRejoin = true;
WarpToGame.GetComponent<WarpToGame>().canRejoinSurvivor1 = true;
WarpToGame.GetComponent<WarpToGame>().canRejoinSurvivor2 = true;
DontAttackManager = true;
DontStartRound = true;
StartRoundBool = false;
StartAttackBool = true;
}
if(timeStartRoundAttack < 0)
{
EndRoundBool = true;
DontAttackManager = false;
ToPManager.GetComponent<ToPManager>().CmdAttack();
StartAttackBool = false;
}
if (timeEndRound < 0 || endBeforeTime == true)
{
EndRoundBool = false;
DontAttackManager = true;
newRound = true;
endBeforeTime = false;
}
if(newRound == true)
{
StartRoundBool = true;
WarpToGame.GetComponent<WarpToGame>().canRejoin = false;
ToPManager.GetComponent<ToPManager>().EndRound();
ToPManager.GetComponent<ToPManager>().CmdTeamWonTime();
StartCoroutine(NewRound(10f));
newRound = false;
}
nextRefreshTime -= Time.deltaTime;
if (nextRefreshTime <= 0)
{
RefreshMatches();
nextRefreshTime = 2;
}
if(currentSelect == Selection.war)
{
playerselected = WarPlayer;
}
if (currentSelect == Selection.minato)
{
playerselected = MinatoPlayer;
}
if (currentSelect == Selection.saitama)
{
playerselected = SaitamaPlayer;
}
if (currentSelect == Selection.goku)
{
playerselected = GokuPlayer;
}
// currentSelect = MinatoButton.GetComponent<CharacterSelectionScreen>().currentSelect;
// Goku = GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected;
// Saitama = SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected;
// War = WarButton.GetComponent<CharacterSelectionScreen>().WarSelected;
}
private void RefreshMatches()
{
if (matchMaker == null);
StartMatchMaker();
matchMaker.ListMatches(0, 10, "", true, 0, 0, HandleListMatchesComplete);
}
public void JoinMatch(MatchInfoSnapshot match)
{
if (matchMaker == null)
StartMatchMaker();
matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, HandleJoinedMatch);
LobbyOption.SetActive(false);
canDontAttackLaunch = true;
}
private void HandleJoinedMatch(bool success, string extendedInfo, MatchInfo responseData)
{
StartClient(responseData);
}
private void HandleListMatchesComplete(bool success, string extendedInfo, List<MatchInfoSnapshot> responseData)
{
AvaibleMatchesList.HandleNewMatchList(responseData);
}
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
// TitleScreen.SetActive(false);
// LobbyOption.SetActive(true);
GameObject player = (GameObject)Instantiate(playerPrefab, SpawnEnter.transform.position, Quaternion.identity);
NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
}
// if (team == 1)
// { player.GetComponent<MinatoController_Net>().team = 1; }
//int team = TeamHandler.GetComponent<TeamHandler>().team;
public void Wargreymon()
{
// LobbySelect.GetComponent<MyLobby>().currentSelect = war;
currentSelect = Selection.war; // changes currentSel to Up.
}
// MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
// SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
// GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
// WarSelected = true;
public void Minato()
{
currentSelect = Selection.minato; // changes currentSel to Up.
// WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
// SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
// GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
// MinatoSelected = true;
}
public void Goku()
{
currentSelect = Selection.goku; // changes currentSel to Up.
// WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
// MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
// SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
// GokuSelected = true;
}
public void Saitama()
{
currentSelect = Selection.saitama; // changes currentSel to Up.
// WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
// MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
//// GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
//SaitamaSelected = true;
}
public void PlayerChoosed(NetworkIdentity player)
{
var conn = player.connectionToClient;
var newPlayer = Instantiate<GameObject>(playerselected);
// LobbyOption.SetActive(false);
Destroy(player.gameObject);
NetworkServer.ReplacePlayerForConnection(conn, newPlayer, 0);
}
public IEnumerator NewRound(float waitTime)
{
yield return new WaitForSeconds(waitTime);
DontStartRound = false;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class OriginalPlayerPrefab : NetworkBehaviour {
public enum Selection { none, minato, saitama, goku, war };
public Selection currentSelect;
public GameObject playerselected;
public GameObject MinatoPlayer;
public GameObject SaitamaPlayer;
public GameObject GokuPlayer;
public GameObject WarPlayer;
public GameObject SpawnPoint2;
// Use this for initialization
void Start ()
{
SpawnPoint2 = GameObject.FindWithTag("SpawnPoint2");
}
// Update is called once per frame
void Update () {
if (currentSelect == Selection.war)
{
playerselected = WarPlayer;
}
if (currentSelect == Selection.minato)
{
playerselected = MinatoPlayer;
}
if (currentSelect == Selection.saitama)
{
playerselected = SaitamaPlayer;
}
if (currentSelect == Selection.goku)
{
playerselected = GokuPlayer;
}
if (Input.GetButtonDown("WarButton"))
{
Wargreymon();
}
if (Input.GetButtonDown("MinatoButton"))
{
Minato();
}
if (Input.GetButtonDown("SwitchCharacter"))
{
CmdSpawn();
}
}
[Command]
public void CmdSpawn()
{
GameObject go = (GameObject)Instantiate(playerselected, SpawnPoint2.transform.position, Quaternion.identity);
NetworkServer.SpawnWithClientAuthority(go, connectionToClient);
}
public void Wargreymon()
{
// LobbySelect.GetComponent<MyLobby>().currentSelect = war;
currentSelect = Selection.war; // changes currentSel to Up.
}
// MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
// SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
// GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
// WarSelected = true;
public void Minato()
{
currentSelect = Selection.minato; // changes currentSel to Up.
// WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
// SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
// GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
// MinatoSelected = true;
}
public void Goku()
{
currentSelect = Selection.goku; // changes currentSel to Up.
// WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
// MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
// SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
// GokuSelected = true;
}
public void Saitama()
{
currentSelect = Selection.saitama; // changes currentSel to Up.
// WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
// MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
//// GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
//SaitamaSelected = true;
}
}
You think the local authority is assigned but my code got a problem?