Can't find namespace even when having the 'using'? - c#

I am using Unity and I'm getting a 'The type or namespace name 'Mine' could not be found (are you missing a using directive or an assembly reference?)' error. I know this means that you are usually missing a using statement, but this is not the case this time. Take a look at the beginning of the 2 script at question. The error is flagged at "public WarmList list;"
using UnityEngine;
using Mine;
namespace PolymindGames.BuildingSystem
{
[RequireComponent(typeof(CookingStation))]
//public class CampfireEffects : MonoBehaviour
public sealed class CampfireEffects : MonoBehaviour
{
public WarmList list;
...
}
}
And script 2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mine
{
public class WarmList : MonoBehaviour
{...
}
}
Why can't script one see class 2? I don't think I am doing anything wrong? I have tried so many solutions but nothing works, I keep getting that complier error.

Related

I was getting 3 errors when following a tutorial and I don't know how to fix them

These are my 3 errors that I have:
Assets/Scripts/Controllers/PlayerController.cs(13,27): error CS0115: 'PlayerController.RetrieveMoveInput()': no suitable method found to override
Assets/Scripts/Controllers/PlayerController.cs(8,26): error CS0115: 'PlayerController.RetrieveJumpInput()': no suitable method found to override
Assets/Scripts/Controllers/PlayerController.cs(6,33): error CS0246: The type or namespace name 'InputController' could not be found (are you missing a using directive or an assembly reference?)
This was the video I was watching: https://www.youtube.com/watch?v=lcw6nuc2uaU&t=140s
These are my 2 scripts:
InputController:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Input : ScriptableObject
{
public abstract float RetrieveMoveInput();
public abstract bool RetrieveJumpInput();
}
PlayerController:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "PlayerController", menuName = "InputController/PlayerController")]
public class PlayerController : InputController
{
public override bool RetrieveJumpInput()
{
return Input.GetButtonDown("Jump");
}
public override float RetrieveMoveInput()
{
return Input.GetAxisRaw("Horizontal");
}
}
Sorry if I've not formatted this correctly, haven't been on here in so long!
You've made a typo depending on how you want to view it should be either:
//wrong class declaration
public abstract class Input : ScriptableObject
{...}
//correct class declaration (how it is written in the github of the tutorial)
public abstract class InputController : ScriptableObject
{...}
alternatively you could also do
//corrected class declaration in other script
public class PlayerController : Input
However I would advise against that and use the tutorial variant, because Input is already a default Unity class that is used for input devices and you'll just be confusing yourself and the compiler.

Unity - get the dropdown in child

I want to get the dropdown which is a child of OperationContainer.
My code gives the error "GameObject' does not contain a definition for 'dropdown' and no accessible extension method 'dropdown' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)".
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AddToPC : MonoBehaviour
{
public GameObject OperationContainer;
void get_instruction(){
Dropdown function = OperationContainer.transform.GetChild(0).gameObject.dropdown;
}
}
}
Make sure your Dropdown component is attached to the children gameObject and try:
Dropdown function = OperationContainer.transform.GetComponentInChildren<Drompdown()>();

Assets/Scripts/Quıt.cs(10,21): error CS0117: 'Application' does not contain a definition for 'Quıt'

I started playing games for the first time in Unity. I get the error in the title. Why could it be? Thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.SceneManagement;
public class Quıt : MonoBehaviour
{
{
Application.Quıt();
}
}
It looks like you just need to put it in a method. Also Application.Quit() does not work in the editor.
public class Quit : MonoBehaviour {
public void QuitApplication() {
Application.Quit();
}
}
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods
https://docs.unity3d.com/Manual/MobileOptimizationScriptingMethods.html

Unable to detect error while using PhotonView.isMine method

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using System.IO;
using UnityEngine.UI;
public class PhotonPlayerSetup : MonoBehaviourPunCallbacks, IInRoomCallbacks
{
private PhotonView PV;
void Awake()
{
PV = GetComponent<PhotonView>();
}
void Start()
{
if(PV.isMine)
{
}
}
}
While using above mentioned code this error appears:
"PhotonView does not contain a definition for isMine and no
accessible extension method isMine accepting a first argument of
type 'PhotonView' could be found (are you missing a using directive or
an assembly reference?)"
Thank you for choosing Photon!
PhotonView.isMine from PUN Classic was renamed to PhotonView.IsMine in PUN 2.
Make sure to check out the Migration Notes.

C# cant find a unity auto generated class

Okay so I'm learning to use the new InputActions and I've created a C# scripts using
https://prnt.sc/oyaj5l
And this is what I got:
// GENERATED AUTOMATICALLY FROM 'Assets/PlayerControls.inputactions'
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class PlayerControls : IInputActionCollection
{
private InputActionAsset asset;
public PlayerControls()
{
///
}
}
But when I try to create an PlayerControls object, I get an error saying
The type or namespace name 'PlayerControls' could not be found (are you missing a using directive or an assembly reference?)
This is the class where I try to reference it:
using System;
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
using UnityEngine.InputSystem;
namespace UnityStandardAssets.Characters.FirstPerson
{
public class FirstPersonController : MonoBehaviour
{
private PlayerControls controls; // ERROR HERE
}
}
Wrap the PlayerControls class in a namespace, then add a using statement in your class that points to the namespace where your PlayerControls class lives.
I solved it!
It looks like Unity has a compile order. I referenced this: http://answers.unity.com/answers/1274460/view.html and managed to solve it after seeing that "Standard Assets" has priority over other assets

Categories

Resources