I have recently been following a tutorial series on Procedurally Generated world generation, I am fairly new to coding and I have come across the following problem. I have 3 error messages in my code,
The first error says:
Error CS0115 'MapGeneratorEditor.OnInspectorGUI()': no suitable method found to override
The second says:
Error CS0103 The name 'target' does not exist in the current context
And the third error is:
Error CS0103 The name 'DrawDefaultInspector' does not exist in the current context
I think that these are somehow related to each other
I am using Unity 2019.4.16f1 personal and here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class MapGeneratorEditor : MonoBehaviour
{
public override void OnInspectorGUI()
{
MapGenerator mapGen = (MapGenerator)target;
DrawDefaultInspector();
if(GUILayout.Button("Generate"))
{
mapGen.GenerateMap();
}
}
}
You are inheriting your MapGeneratorEditor class from MonoBehavior, but OnInspectorGUI function only member of Editor class. You should replace MonoBehavior with Editor
MapGeneratorEditor:Editor
here is referances where your functions comes
OnInspectorGUI
DrawDefaultInspector
Related
I'm trying to do a script that when the player pass by a item, it activates it's effect in the player.
But this error apears:
This is my code:
`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Bonus : MonoBehaviour
{
public string name;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Player"))
{
collision.SendMessage(name, null, SendMessageOptions.RequireReceiver);
Destroy(gameObject);
}
}
}
`
I already tried adding the
SendMessageOptions.RequireReceiver
but it didn't work
What the error is trying to tell you is:
On your collision's GameObject there is no component attached that implements a method called whatever the value of name is (in your case doubleSpeed).
By default the option already is SendMessageOptions.RequireReceiver, if there is none you get that error message.
The receiving method can choose to ignore the argument by having zero parameters. If options is set to SendMessageOptions.RequireReceiver an error is printed if the message is not picked up by any component.
If you want to ignore the case where there is no receiver you would rather pass in SendMessageOptions.DontRequireReceiver
In general instead of using SendMessage at all rather get your component and call the method directly
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 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.
I'm fairly new to C# and unity, and i've been trying to set up the Photon Networking service. I've run into an issue i can't figure out the cause of. Here are the two error messages.
Assets\PhotonUnityNetworking\Resources\TestConnect.cs(21,41): error CS0246: The Type or namespace name 'DisconnectCause' could not be found (are you missing a using directive or an assembly reference?)
Asseta\PhotonUnityNetworking\Resources\TestConnect.cs(21,26): error CS0115 'TestConnect.OnDisconnected(DisconnectCause)': no suitable method found to override.
However, in visual studio, nothing shows up as incorrect.
Any help as to the cause of these issues appreciated.
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestConect : MonoBehaviourPunCallbacks
{
private void Start()
{
print("Connecting to server...");
PhotonNetwork.GameVersion = "0.0.1";
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
print("Connected to server!");
}
public override void OnDisconnected(DiconnectionCause cause)
{
print("Disconnected from Server for reason " + cause.ToString());
}
}
First another important note: You should not put any of your custom scripts inside a folder called Resources!
Also afaik PhotonUnityNetworking is their official folder of Photon itself. I'ld recommend to not modify or add anything within it, makes it hard to upgrade or fix it later if you have messed it up somehow.
Then to your issue
It is as the error already suggests
are you missing a using directive
DisconnectCause belongs to another namespace Photon.Realtime.
You will need to add a
using Photon.Realtime;
on the top of that file or have to address it directly like
public override void OnDisconnected(Photon.Realtime.DisconnectCause cause)
{
...
}
Strange though that VisualStudio doesn't note that...
The second error is just a follow-up compile error not finding the according method to override because of a supposed signature mismatch since it doesn't know the type you used as parameter due to the error before.
In the future please don't post screenshots of code and error messages! This makes it not only harder to solve the issue but also makes it impossible for others to find this thread when searching for the error message content in order to see if it was already solved somewhere!
Rather copy & paste the raw text I your question and format it as code using the { } button.
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);
}
}