Unable to configure saving and loading with firebase - c#

I followed all steps such as adding the database SDK to Unity etc., but when I try to connect Unity to Firebase, I'm getting an error.
Assets\Script\RealTimeLoading.cs(14,21): error CS0029: Cannot implicitly convert type 'Firebase.Database.DatabaseReference' to 'DatabaseReference'
I followed a lot of tutorials, they are never getting errors, just me. Here is my code
using Firebase;
using Firebase.Database;
using Firebase.Unity.Editor;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RealTimeLoading : MonoBehaviour
{
DatabaseReference reference;
// Start is called before the first frame update
void Start()
{
reference = FirebaseDatabase.DefaultInstance.RootReference;
}
// Update is called once per frame
void Update()
{
}
}
The error is on this line:
FirebaseDatabase.DefaultInstance.RootReference;
What did I do wrong?

After briefly going through your using statements, I don't believe that there should be a DatabaseReference other than the one in Firebase.Database. That makes me think that you have another class in your project's root namespace with the same name.
First, I'd recommend removing Firebase.Unity.Editor and definitely let me know if there's still some documentation recommending it.
Then you should be able to simply write:
using DatabaseReference = Firebase.Database.DatabaseReference;
with your other using directives. So the top of your file may look like:
using Firebase;
using Firebase.Database;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DatabaseReference = Firebase.Database.DatabaseReference;
Be careful with this because if there is another class named DatabaseReference in your code base, you may run into this naming conflict more often. It could be beneficial to either move it to its own namespace or to rename it if possible. But this should get you unstuck immediately.
Alternatively: instead of adding the using alias, you may instead fully qualify the name in your class. For example:
using Firebase;
using Firebase.Database;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RealTimeLoading : MonoBehaviour
{
Firebase.Database.DatabaseReference reference;
// Start is called before the first frame update
void Start()
{
reference = FirebaseDatabase.DefaultInstance.RootReference;
}
}
I would recommend against doing both of these in one file, but you may have to use each under different circumstances.

Related

The type or namespace name 'ThirdPersonUserControl' could not be found (are you missing a using directive or an assembly reference?)

I'm creating a Third Person joystick controller
but I can't figure out this error.
code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonInput : MonoBehaviour
{
public FixedJoystick LeftJoystick;
public FixedButton Button;
public ThirdPersonUserControl Control;
// Start is called before the first frame update
void Start()
{
Control = GetComponent<ThirdPersonUserControl>();
}
// Update is called once per frame
void Update()
{
Control.m_Jump = Button.Pressed;
Control.Hinput = LeftJoystick.inputVector.x;
Control.Vinput = LeftJoystick.inputVector.y;
}
}
Please help...
I ssume you copied this from some quite old source.
There was a UnityStandardAssets.Characters.ThirdPerson.ThirdPersonUserControl as the name suggests in the StandardAssets.
The last supported Unity version is 2018.4 though since afaik the concept of the "Standard" assets was given up by then.
So if you are still happen to use that version then just import the StandardAssets via the Asset Store and in your script add
using UnityStandardAssets.Characters.ThirdPerson;
in newer Unity versions you might want to rather give it a shot with Starter Assets - Third Person Character Controller instead.

I've got error CS0234 when I tried to build my 2D project in Unity

I'am new in Unity, so don't be angry)
I tried to build my game, but I've got those errors:
-Assets\Scripts\PlayerMovement.cs(5,19): error CS0234: The type or namespace name 'WSA' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
-Assets\Scripts\SpawnMovePoint.cs(4,19): error CS0234: The type or namespace name 'Build' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
-Error building Player because scripts had compiler errors
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Build.Reporting; // Problem Line
using UnityEngine;
using UnityEngine.SceneManagement;
public class SpawnMovePoint : MonoBehaviour
{
public Transform left, right, _point;
float MinX, MaxX;
public void Start()
{
MinX = left.position.x;
MaxX = right.position.x;
}
public void CreatePoint()
{
_point.position = new Vector3(Random.Range(MinX,
MaxX),_point.position.y,_point.position.z);
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine.WSA;//Problem Line
public class PlayerMovement : MonoBehaviour
What should I do to fix them?
How can I make these references?
What does it mean, what 'Build' does not exist in 'UnityEditor'?
'-Error building Player because scripts had compiler errors'
This simply means that the script cannot be compiled because it contains some errors, pretty straight forward.
Can you tell me why do you need 'UnityEditor.Build.Reporting and WSA ??
Also, you should share more code so we can see where and why you are using a certain namespace and whether the code will work without them or not.
Please Include more information to help me as well as others to understand and help fix your problem. Make sure to also show any research you have done to try and fix this problem.

SceneChange script compiler error: unable to access due to protection level

I have this script that allows me to change to a different scene when I push a button. I've used it multiple times before with no issue, but recently I've been getting this compiler error that's telling me the script can't be accessed due to its protect level. I did some research and it supposedly means something is set to private instead of public, but everything in my script is public to begin with. Please help? According to Unity, the error is the ".LoadScene" inside public void DoSceneChange().
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneChange : MonoBehaviour
{
[SerializeField]
string levelToLoad;
public void DoSceneChange()
{
SceneManager.LoadScene(levelToLoad);
}
}

AdEventListener does not exist in the type StartApp.StartAppWrapper

I am getting the following error in unity , I tried to refresh the project and to see any suggestion solution but still the same error
Assets/Plugins/Scripts/AdsManager.cs(10,43): error CS0426: The nested
type `AdEventListener' does not exist in the type
StartApp.StartAppWrapper
Here is the code:
using UnityEngine;
using GoogleMobileAds.Api;
using ChartboostSDK;
using System;
using StartApp;
using UnityEngine.Advertisements;
using SATestAds;
using UnityEngine;
using GoogleMobileAds.Api;
using ChartboostSDK;
using System;
using StartApp;
using UnityEngine.Advertisements;
using SATestAds;
public class AdsManager : StartAppWrapper.AdEventListener
{
private bool testMode = false;
private bool loggerEnabled = false;
private float delay = 0f;
}
AdEventListener is an interface which requires the following conditions be met before you can use it:
1.That your Unity version is Unity 4.2 and above.
2.That your current Platform is set to Android. Go to File --> Build Settings..., select Android and click the Switch Platform button. This is likely the issue.
Both of these checks are being done with Unity's preprocessor directives such as UNITY_ANDROID and UNITY_4_1. That interface is only declared when both are true.
Note that this answer assumes that you have already imported the StartApp-SDK. If you have not, you can get that here.

I cant get SevenZipLib library to work (p/invoke)

Very basic knowledge on c# and is the first i use anything p/invoke related.
Help me pls, i have made this code but it doesnt seem to work.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[DllImport("C:\\Users\\lchris\\Desktop\\SevenZipLib_9.13.2\\SevenZipLib\\SevenZipLib\\7z86.dll")]
public static extern void SevenZipArchive(string c);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SevenZipArchive archive = new SevenZipArchive("file.rar"))
{
foreach (ArchiveEntry entry in archive)
{
Console.WriteLine(entry.FileName);
}
}
}
}
}
It tells me that SevenZipArchive is a 'Method' and is being used like a 'type'.
I have include the library to my project already, i just dont know how to use it.
Here is the library:
https://sevenziplib.codeplex.com/
You first need to remove this code:
[DllImport("...")]
public static extern void SevenZipArchive(string c);
You do not need to provide any p/invoke declarations. The library wraps that up for you.
This is a .net assembly. You use it just as you use any other. Take the following steps:
Download the project. You already did that I think.
Build the solution. Make sure that
In your project, add a reference to the assembly that you built in the previous stage. It's SevenZipLib\bin\Debug\SevenZipLib.dll or SevenZipLib\bin\Release\SevenZipLib.dll depending on the target you selected.
Add using SevenZipLib; to your project code to to gain access to the namespace.
Once you've done that your code will work. You can use the tests project that is supplied as part of the download as a rich source of example code.

Categories