Unity C#代码未检测到问题。

huangapple go评论65阅读模式
英文:

Unity C# Codes Not Detecting Issue

问题

I started Unity C# training today, but I have a problem. I created an empty object named "_scripts" and created a C# file named "Encoding" and put it into it. Even though I write the codes and run the program, I can't get any output. As an editor, I added the codes and images below with Visual Studio 2019 selected.

Image 1:

Image 2:

Code:

// kodlari calismasi icin gerekli komutlar
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Kodlama : MonoBehaviour
{
    int sayiDegerleri = 5;
    bool oyunBasladi = false;
    void Start() // program calistiginda sadece 1 kere calistirilir
    {
        if (sayiDegerleri == 5) // sayi degeri 5 ise
            Debug.Log("Değeriniz 5"); //  5 ise cikti
        else if (sayiDegerleri == 4) // eger yukaridaki degil buysa
            Debug.Log("Değeriniz 4"); // 4 ise cikti
        else // eger ikisi de degilse
            Debug.Log("Değeriniz 4 veya 5 Değil"); // cikti
    }
 
    void Update() // 30 framelik bir programda saniyede 30 kere calistirilir
    {
         
    }
}

I want Unity to detect when I save my C# code. If they perceive it, I will continue my education and learn.

英文:

I started Unity C# training today, but I have a problem. I created an empty object named _scripts and created a C# file named "Encoding" and put it into it. Even though I write the codes and run the program, I can't get any output. As an editor, I added the codes and images below with visual studio 2019 selected.

Image 1:

Image 2:

Code:

// kodlari calismasi icin gerekli komutlar
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Kodlama : MonoBehaviour
{
    int sayiDegerleri = 5;
    bool oyunBasladi = false;
    void Start() // program calistiginda sadece 1 kere calistirilir
    {
        if (sayiDegerleri == 5) // sayi degeri 5 ise
            Debug.Log("Değeriniz 5"); //  5 ise cikti
        else if (sayiDegerleri == 4) // eger yukaridaki degil buysa
            Debug.Log("Değeriniz 4"); // 4 ise cikti
        else // eger ikisi de degilse
            Debug.Log("Değeriniz 4 veya 5 Değil"); // cikti
    }
 
    void Update() // 30 framelik bir programda saniyede 30 kere calistirilir
    {
         
    }
}

I want Unity to detect when I save my C# code. If they perceive it, I will continue my education and learn.

答案1

得分: 1

你处于游戏模式!

默认情况下,Unity在游戏模式下不会重新编译脚本。

退出游戏模式,Unity将重新编译。

英文:

You are in Play mode!

Per default Unity doesn't recompile scripts while you are in Play mode.

Exit play mode and Unity will recompile.

答案2

得分: 0

Sure, here's the translated text:

嗯...
我们可以检查层次结构中的“_scripts”对象是否有名为“Kodlama.cs”的C#脚本,这正是我们刚刚编写的吗?

如果是的话,问题可能是我们编写的Kodlama.cs在运行时没有应用

根据您上传的截图,
Kodlama.cs”有一个在初始化时生成的脚本,而不是我们修改过的代码。

如果您仔细检查这些部分并纠正问题,
您将得到您想要的结果。

我希望这个答案能帮助您解决问题,
祝您有一个宁静的一天。

英文:

Hmm..
Could we check the "_scripts" Object in Hierarchy have C# script named "Kodlama.cs" that we just wrote?

Unity C#代码未检测到问题。

if then, the problem would be the change of Kodlama.cs that we wrote wouldn't apply in the runtime

according to the Screenshot that you uploaded,
"Kodlama.cs" has a script that it just generated in initialization, not the code we modified.
Unity C#代码未检测到问题。

If you check these parts carefully and rectify the problem,
you would get the result that you wanted.

I hope that this answer would help you solve the problem,
and have a peaceful day.

答案3

得分: -1

Make sure your class name in Visual Studio matches the script file name in the project tab.

Then try this:

void Start()
{
    sayiDegerleri = 5;

    if (sayiDegerleri == 5) // If the numeric value is 5
        Debug.Log("Your value is 5"); // Output if it's 5
    else if (sayiDegerleri == 4) // If it's not the above, and it's 4
        Debug.Log("Your value is 4"); // Output if it's 4
    else // If neither of the above conditions is met
        Debug.Log("Your value is not 4 or 5"); // Output
}
英文:

Make sure your class name in visual studio match script file
name in project tab

Then try this:

void start()
{
    sayiDegerleri = 5;

    if (sayiDegerleri == 5) // sayi degeri 5 ise
        Debug.Log("Değeriniz 5"); //  5 ise cikti
    else if (sayiDegerleri == 4) // eger yukaridaki degil buysa
        Debug.Log("Değeriniz 4"); // 4 ise cikti
    else // eger ikisi de degilse
        Debug.Log("Değeriniz 4 veya 5 Değil"); // cikti

}

huangapple
  • 本文由 发表于 2023年5月15日 09:58:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76250446.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定