Pedor 0 / 0 / 0 Регистрация: 18.04.2021 Сообщений: 5 |
||||
1 |
||||
22.04.2021, 15:40. Показов 5955. Ответов 6 Метки unity (Все метки)
Ошибка в коде помогите пожалуйста найти её. Заранее спасибо!
__________________
0 |
2496 / 1512 / 803 Регистрация: 23.02.2019 Сообщений: 3,689 |
|
22.04.2021, 16:16 |
2 |
А какая ошибка, лишний пробел?
0 |
0 / 0 / 0 Регистрация: 18.04.2021 Сообщений: 5 |
|
22.04.2021, 17:00 [ТС] |
3 |
Нет
0 |
2496 / 1512 / 803 Регистрация: 23.02.2019 Сообщений: 3,689 |
|
22.04.2021, 17:14 |
4 |
Вы можете просто скопировать текст ошибки в сообщение?
0 |
0 / 0 / 0 Регистрация: 18.04.2021 Сообщений: 5 |
|
22.04.2021, 17:35 [ТС] |
5 |
Ах да, извинит- error CS0103:The name ‘SceneManager’ does not exist current context-Имя SceneManager не существует в текущем контексте
0 |
samana 2496 / 1512 / 803 Регистрация: 23.02.2019 Сообщений: 3,689 |
||||
22.04.2021, 18:11 |
6 |
|||
РешениеВы не прописали пространство имён
1 |
0 / 0 / 0 Регистрация: 18.04.2021 Сообщений: 5 |
|
22.04.2021, 18:13 [ТС] |
7 |
Блин.. Спасибо большое!
0 |
Permalink
Cannot retrieve contributors at this time
description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Compiler Error CS0103 |
Compiler Error CS0103 |
07/20/2015 |
CS0103 |
CS0103 |
fd1f2104-a945-4dba-8137-8ef869826062 |
Compiler Error CS0103
The name ‘identifier’ does not exist in the current context
An attempt was made to use a name that does not exist in the class, namespace, or scope. Check the spelling of the name and check your using directives and assembly references to make sure that the name that you are trying to use is available.
This error frequently occurs if you declare a variable in a loop or a try
or if
block and then attempt to access it from an enclosing code block or a separate code block, as shown in the following example:
[!NOTE]
This error may also be presented when missing thegreater than
symbol in the operator=>
in an expression lambda. For more information, see expression lambdas.
using System; class MyClass1 { public static void Main() { try { // The following declaration is only available inside the try block. var conn = new MyClass1(); } catch (Exception e) { // The following expression causes error CS0103, because variable // conn only exists in the try block. if (conn != null) Console.WriteLine("{0}", e); } } }
The following example resolves the error:
using System; class MyClass2 { public static void Main() { // To resolve the error in the example, the first step is to // move the declaration of conn out of the try block. The following // declaration is available throughout the Main method. MyClass2 conn = null; try { // Inside the try block, use the conn variable that you declared // previously. conn = new MyClass2(); } catch (Exception e) { // The following expression no longer causes an error, because // the declaration of conn is in scope. if (conn != null) Console.WriteLine("{0}", e); } } }
C# Compiler Error
CS0103 – The name ‘identifier’ does not exist in the current context
Reason for the Error
You will usually receive this error when you are trying to use a identifier name in C# that doesnot exist with-in the current scope. One of the simple example of this error is when you declare a variable with-in a try block and try to access it in the catch block.
In the below example, the variable i is declared inside the try block, so its scope is restricted to the try block. When you try accessing it in the catch block is when you will receive the error.
using System; public class DeveloperPublish { public static void Main() { try { int i = 1; int j = 0; int result = i / j; } catch(DivideByZeroException) { string message = i + " is divivided by zero"; Console.WriteLine(message); } } }
Error CS0103 The name ‘i’ does not exist in the current context ConsoleApp1 C:UsersSenthilsourcereposConsoleApp1ConsoleApp1Program.cs 16 Active
Solution
To fix the error move the declaration of the identifier that is causing the error to a higher scope so that it is available when it is accessed.
For example, to fix the error in the above code snippet, we just need to move the declaration of the identifier outside of the try block.
using System; public class DeveloperPublish { public static void Main() { int i = 1; try { int j = 0; int result = i / j; } catch(DivideByZeroException) { string message = i + " is divivided by zero"; Console.WriteLine(message); } } }
When my view loads, I need to check which domain the user is visiting, and based on the result, reference a different stylesheet and image source for the logo that appears on the page.
This is my code:
@{
string currentstore=HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
if (currentstore == "www.mydomain.com")
{
<link href="/path/to/my/stylesheets/styles1-print.css" rel="stylesheet" type="text/css" />
string imgsrc="/content/images/uploaded/store1_logo.jpg";
}
else
{
<link href="/path/to/my/stylesheets/styles2-print.css" rel="stylesheet" type="text/css" />
string imgsrc="/content/images/uploaded/store2_logo.gif";
}
}
Then, a little further down I call the imgsrc variable like this:
<a href="@Url.RouteUrl("HomePage")" class="logo"><img alt="" src="@imgsrc"></a>
I get an error saying:
error CS0103: The name ‘imgsrc’ does not exist in the current context
I suppose this is because the «imgsrc» variable is defined in a code block which is now closed…?
What is the proper way to reference this variable further down the page?
asked Sep 26, 2014 at 20:23
Simply move the declaration outside of the if block.
@{
string currentstore=HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
string imgsrc="";
if (currentstore == "www.mydomain.com")
{
<link href="/path/to/my/stylesheets/styles1-print.css" rel="stylesheet" type="text/css" />
imgsrc="/content/images/uploaded/store1_logo.jpg";
}
else
{
<link href="/path/to/my/stylesheets/styles2-print.css" rel="stylesheet" type="text/css" />
imgsrc="/content/images/uploaded/store2_logo.gif";
}
}
<a href="@Url.RouteUrl("HomePage")" class="logo"><img alt="" src="@imgsrc"></a>
You could make it a bit cleaner.
@{
string currentstore=HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
string imgsrc="/content/images/uploaded/store2_logo.gif";
if (currentstore == "www.mydomain.com")
{
<link href="/path/to/my/stylesheets/styles1-print.css" rel="stylesheet" type="text/css" />
imgsrc="/content/images/uploaded/store1_logo.jpg";
}
else
{
<link href="/path/to/my/stylesheets/styles2-print.css" rel="stylesheet" type="text/css" />
}
}
answered Sep 26, 2014 at 20:26
masonmason
31.1k10 gold badges76 silver badges120 bronze badges
0
using System;
using System.Collections.Generic; (помогите пожалуйста та же самая
using System.Linq; ошибка PlayerScript.health =
using System.Text; 999999; вот на этот скрипт)
using System.Threading.Tasks;
using UnityEngine;
namespace OneHack
{
public class One
{
public Rect RT_MainMenu = new Rect(0f, 100f, 120f, 100f); //Rect это месторасположение меню по x,y и высота, ширина.
public int ID_RTMainMenu = 1;
private bool MainMenu = true;
private void Menu_MainMenu(int id) //Главное меню
{
if (GUILayout.Button("Название вашей кнопки", new GUILayoutOption[0]))
{
if (GUILayout.Button("Бессмертие", new GUILayoutOption[0]))
{
PlayerScript.health = 999999;//При нажатии на кнопку у игрока устанавливается здоровье 999999 //Здесь код, который будет происходить при нажатии на эту кнопку
}
}
}
private void OnGUI()
{
if (this.MainMenu)
{
this.RT_MainMenu = GUILayout.Window(this.ID_RTMainMenu, this.RT_MainMenu, new GUI.WindowFunction(this.Menu_MainMenu), "MainMenu", new GUILayoutOption[0]);
}
}
private void Update() //Постоянно обновляемый метод, все что здесь будет написанно будет создаваться бесконечно
{
if (Input.GetKeyDown(KeyCode.Insert)) //Кнопка на которую будет открываться и закрываться меню, можно поставить другую
{
this.MainMenu = !this.MainMenu;
}
}
}
}
Suraj Rao
29.3k11 gold badges96 silver badges103 bronze badges
answered Aug 31, 2020 at 9:26
4
как узнать имя сцены в которой находишься ?
как узнать имя сцены в которой находишься ?
я хочу узнать название сцены и использовать это в условии if
нашел что-то «SceneManager.GetActiveScene().name» вот , но как сделать чтобы было так if (SceneManager.GetActiveScene().name==main)
- kirya_355
- UNIт
- Сообщения: 106
- Зарегистрирован: 09 май 2018, 21:40
Re: как узнать имя сцены в которой находишься ?
1max1 27 июн 2018, 12:41
что такое main? имя сцены это строка, вот строки и сравнивай
-
1max1 - Адепт
- Сообщения: 5285
- Зарегистрирован: 28 июн 2017, 10:51
Re: как узнать имя сцены в которой находишься ?
kirya_355 27 июн 2018, 12:57
1max1 писал(а):что такое main? имя сцены это строка, вот строки и сравнивай
main это название сцены , как их стравнить ,
Используется csharp
public string main;
void Start(){
if(SceneManager.GetActiveScene().name!=main){
……}
}
так что-ли,
- kirya_355
- UNIт
- Сообщения: 106
- Зарегистрирован: 09 май 2018, 21:40
Re: как узнать имя сцены в которой находишься ?
1max1 27 июн 2018, 13:17
Ну да)) Странный вопрос если честно, можешь еще через string.Equals сравнивать, но это уже слишком пафосно я думаю
-
1max1 - Адепт
- Сообщения: 5285
- Зарегистрирован: 28 июн 2017, 10:51
Re: как узнать имя сцены в которой находишься ?
kirya_355 27 июн 2018, 13:19
1max1 писал(а):Ну да)) Странный вопрос если честно, можешь еще через string.Equals сравнивать, но это уже слишком пафосно я думаю
но unity ругается на это
error CS0103: The name `SceneManager’ does not exist in the current context
- kirya_355
- UNIт
- Сообщения: 106
- Зарегистрирован: 09 май 2018, 21:40
Re: как узнать имя сцены в которой находишься ?
1max1 27 июн 2018, 13:30
может пространство имен не добавил просто
using UnityEngine.SceneManagement;
-
1max1 - Адепт
- Сообщения: 5285
- Зарегистрирован: 28 июн 2017, 10:51
Re: как узнать имя сцены в которой находишься ?
kirya_355 27 июн 2018, 13:43
1max1 писал(а):может пространство имен не добавил просто
using UnityEngine.SceneManagement;
спасибо всё работает
вот код кому нужно
Используется csharp
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
void OnMouseUpAsButton(){
if (SceneManager.GetActiveScene().name != «main»)
Application.LoadLevel(«game»);
}
- kirya_355
- UNIт
- Сообщения: 106
- Зарегистрирован: 09 май 2018, 21:40
Вернуться в Почемучка
Кто сейчас на конференции
Сейчас этот форум просматривают: Yandex [Bot] и гости: 24
- Index
- Recent Topics
- Search
-
Log in
- Forum
- Plugins
-
I2 Localization
- `SceneManager’ error after update
5 years 8 months ago — 5 years 8 months ago #2261
by Sarr
Hello,
I’ve just updated I2 Localization through Unity’s updater (after removing folders Common and Localization).
Now I get error:
Assets/I2/Common/Editor/EditorTools.cs(533,12): error CS0103: The name `SceneManager’ does not exist in the current context
Don’t really know how to solve it.
Could you help a bit?
EDIT: Wow, it seems you forgot to add «using UnityEngine.SceneManagement;» on top of that script. After adding that line, no errors yet.
Last edit: 5 years 8 months ago by Sarr.
Please Log in or Create an account to join the conversation.
5 years 8 months ago #2262
by Frank
Hi,
There was a last minute change in that version, that caused that error.
You can fix it by downloaded 2.6.12f2 from the beta folder (I already submitted it to the AssetStore, but will take a few days to be approved)
Nonetheless, a manual way of fixing it is by replacing the first line in the EditorTools.cs by this one:
#if !(UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2) using UnityEngine.SceneManagement; #endif
Version 2.6.12f2 also has a few other other fixes/improvements.
Hope that helps,
Frank
Are you Give I2L
5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
Please Log in or Create an account to join the conversation.
- Forum
- Plugins
-
I2 Localization
- `SceneManager’ error after update
Time to create page: 0.167 seconds