- Home /
So much compiler errors
(I'm not English but French)
I got compiler errors but I can't solve without help (plz)
The compiler errors say that the type "GameObject" doesn't contain definitions of SetActive so I can't use SetActive, FindGameObjectsWithTag neither. I also, ".gameObject" doesn't work. I can't continue with these problems !
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RoomListing : MonoBehaviour
{
[SerializeField]
private Text _roomNameText;
private Text RoomNameText
{
get { return _roomNameText; }
}
[SerializeField]
private Text _gamemodeText;
private Text GamemodeText
{
get { return _gamemodeText; }
}
[SerializeField]
private Text _currentPlayersText;
private Text CurrentPlayersText
{
get { return _currentPlayersText; }
}
public string RoomName { get; private set;}
public string GameMode { get; private set; }
public string CurrentPlayers { get; private set; }
public bool Updated { get; set; }
public Button JoinButton;
private void Start ()
{
GameObject lobbyCanvasObj = MainCanvasManager.Instance.LobbyCanvas.gameObject;
if (lobbyCanvasObj == null)
{
return;
}
JoinButton = GetComponent<Button>();
LobbyCanvas lobbyCanvas = lobbyCanvasObj.GetComponent<LobbyCanvas>();
JoinButton.onClick.AddListener (() => lobbyCanvas.OnClickJoinRoom (RoomNameText.text));
}
private void OnDestroy()
{
JoinButton.onClick.RemoveAllListeners();
}
public void SetRoomNameText(string text)
{
RoomName = text;
RoomNameText.text = RoomName;
}
public void SetGamemodeText(string text)
{
GameMode = text;
GamemodeText.text = GameMode;
}
public void SetMaxPlayersText(string text)
{
CurrentPlayers = text;
CurrentPlayersText.text = CurrentPlayers + "/4";
}
}
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
public class RoomLayoutGroup : MonoBehaviour
{
[SerializeField]
private GameObject _roomListingPrefab;
private GameObject RoomListingPrefab
{
get { return _roomListingPrefab; }
}
private List<RoomListing> _roomListingButtons = new List<RoomListing>();
private List<RoomListing> RoomListingButtons
{
get { return _roomListingButtons; }
}
private void OnReceivedRoomListUpdate()
{
RoomInfo[] rooms = PhotonNetwork.GetRoomList ();
foreach (RoomInfo room in rooms)
{
RoomReceived(room);
}
RemoveOldRooms();
}
private void RoomReceived(RoomInfo room)
{
int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name);
if (index == -1)
{
if (room.IsVisible && room.PlayerCount < room.MaxPlayers)
{
GameObject roomListingObj = Instantiate(RoomListingPrefab);
roomListingObj.transform.SetParent(transform, false);
RoomListing roomListing = roomListingObj.GetComponent<RoomListing>();
RoomListingButtons.Add(roomListing);
index = (RoomListingButtons.Count - 1);
}
}
if (index != -1)
{
RoomListing roomListing = RoomListingButtons[index];
roomListing.SetRoomNameText(room.Name);
roomListing.Updated = true;
}
}
private void RemoveOldRooms()
{
List<RoomListing> removeRooms = new List<RoomListing>();
foreach (RoomListing roomListing in RoomListingButtons)
{
if (!roomListing.Updated)
{
removeRooms.Add (roomListing);
}
else
{
roomListing.Updated = false;
}
}
foreach (RoomListing roomListing in removeRooms)
{
GameObject roomListingObj = roomListing.gameObject;
RoomListingButtons.Remove (roomListing);
Destroy (roomListingObj);
}
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class SegSackboysLeft : Photon.MonoBehaviour {
GameObject[] SackboyRestants;
GameObject DeadPlayers;
[Header("Canvas")]
public GameObject VictoryText;
public GameObject DefeatText;
public Text SackboysCount;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
SackboyRestants = GameObject.FindGameObjectsWithTag("Sackboy");
SackboysCount.text = SackboyRestants.Length.ToString();
if(SackboyRestants.Length == 0)
{
GameOver();
}
}
void GameOver()
{
DefeatText.SetActive(true);
}
}
Have you got any custom class in your project called GameObject
? If so, rename the class and the file name. Or use the namespaces to reach the Unity's GameObject class
Avez-vous créé un script dans votre projet Unity qui s'appelle GameObject
? Si oui, renommez la classe et le nom du fichier. Ou utilisez les espaces de nom pour atteindre la bonne classe Unity:
UnityEngine.GameObject roomListingObj = roomListing.gameObject;
// ....
UnityEngine.GameObject.FindGameObjectsWithTag("Sackboy");
Answer by agarcia115 · Jun 07, 2018 at 07:13 AM
void GameOver() { DefeatText.SetActive(true); }
If you want to SetActive something it has to be a GameObject, otherwise, you have to write:
DefeatText.enabled = true;
Answer by PandaChaoZ · Sep 09, 2018 at 05:19 PM
I found the problem ! One of my scripts (I forgot to show you, sorry !) was a GameObject and not a MonoBehaviour. I totatlly forgot to show it to you. My apologies !