using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Photon.Pun;
using System.IO;
using System;
public class RoomManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
if (instance)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
instance = this;
}
public override void OnEnable(1)
{
base.OnEnable(1);
SceneManagement.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if(scene.buildIndex == 1)
{
PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs","PlayerManager"), Vector3.zero, Quaternion, identity);
}
}
public override void OnDisable(0)
{
base.OnDisable(0);
}
}
And give error in console:
Assets\Scripts\RoomManager.cs(24,35): error CS1001: Identifier expected
Assets\Scripts\RoomManager.cs(38,36): error CS1001: Identifier expected
It tells you Line 24, Column 35 and Line 38, Column 36.
Why are you putting in a â0â or â1â when defining methods? Thatâs not valid C#. Youâre also not overriding anything so you donât need to specify that nor do you need to call the base.
Sorry but its my error(I tried to do this)
My code now:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Photon.Pun;
using System.IO;
using System;
public class RoomManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
if (instance)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
instance = this;
}
public override void OnEnable()
{
base.OnEnable();
SceneManagement.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if(scene.buildIndex == 1)
{
PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs","PlayerManager"), Vector3.zero, Quaternion, identity);
}
}
public override void OnDisable()
{
base.OnDisable();
}
}
Errors:
Assets\Scripts\RoomManager.cs(24,26): error CS0115: âRoomManager.OnEnable()â: no suitable method found to override
Assets\Scripts\RoomManager.cs(38,26): error CS0115: âRoomManager.OnDisable()â: no suitable method found to override
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Photon.Pun;
using System.IO;
using System;
public class RoomManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
if (instance)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
instance = this;
}
public override void OnEnable()
{
SceneManagement.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if(scene.buildIndex == 1)
{
PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs","PlayerManager"), Vector3.zero, Quaternion, identity);
}
}
}
Error:
Assets\Scripts\RoomManager.cs(24,26): error CS0115: âRoomManager.OnEnable()â: no suitable method found to override
You donât know how to remove the âoverrideâ keyword and you want me to copy your code, remove them and paste it for you? Thatâs not what the forums are for, sorry.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Photon.Pun;
using System.IO;
using System;
public class RoomManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
if (instance)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
instance = this;
}
public void OnEnable()
{
SceneManagement.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if(scene.buildIndex == 1)
{
PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs","PlayerManager"), Vector3.zero, Quaternion, identity);
}
}
}
Errors:
Assets\Scripts\RoomManager.cs(14,13): error CS0103: The name âinstanceâ does not exist in the current context
Assets\Scripts\RoomManager.cs(20,9): error CS0103: The name âinstanceâ does not exist in the current context
Assets\Scripts\RoomManager.cs(26,9): error CS0103: The name âSceneManagementâ does not exist in the current context
Assets\Scripts\RoomManager.cs(33,100): error CS0119: âQuaternionâ is a type, which is not valid in the given context
Assets\Scripts\RoomManager.cs(33,112): error CS0103: The name âidentityâ does not exist in the current context
Youâre not dumb but you seem to be guessing at how to write code which isnât the best approach.
âinstanceâ doesnât exist in the code as the compiler states. How am I supposed to fix it? I didnât write this code so I have no idea what itâs supposed to look like. I know you want answers but there is no answer here.
The forums are not here to write code for you. If you copied this code from somewhere such as a tutorial then youâre missing the point of a tutorial which is to teach you something so if thatâs the case, please go back to the tutorial and follow it again.
You have not defined a class variable called instance, with the level of struggle please find a basic c# tutorial, that explains classes, properties, fields, methods, scope and well, try the learn c# in 24 hours or something book
Note, every error gives you a line number⌠your first duty is to read the error, look up the error and see how it applies to the line.