Çözüldü Unity 2D Visual Studio kod hatası

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

Ymn_75

Femtopat
Katılım
1 Şubat 2024
Mesajlar
34
Daha fazla  
Cinsiyet
Erkek
Oyunun kodunu girdim ama şu hatayı alıyorum Assets/kod.cs(53,6) error CS1513:} expected hatası alıyorum.

Kodum:

Using System. Collections;
Using System. Collections. Generic;
Using unityengine;

Public class kod: Monobehaviour.
{
İnt minsayi = 1;
İnt maxsayi = 100;
İnt tahmin;

// Start is called before the first frame Update.
Void Start()
{
Print("başlatayım mı? (E/H)");
}

// Update is called once per frame.
Void Update()
{
İf (ınput. Getkeydown(keycode. E))
{
Print("1-100 arası bir sayı tut");
}
Else if (Input.GetKeyDown(KeyCode.H)) {
Print("neden hayır dedin!");
}
İf (ınput. Getkeydown(keycode. Return))
{
Kontrol();
}

İf (ınput. Getkeydown(keycode. Uparrow))
{
Minsayi = tahmin;
Tahmin = (minsayi + maxsayi) / 2;
kontrol();
}

İf (ınput. Getkeydown(keycode. Downarrow))
{
Maxsayi = tahmin;
kontrol();
}
Else if (ınput. Getkeydown(keycode. Space)) {
Print("buldum");
}

Void Kontrol() {
Tahmin = (maxsayi + maxsayi) / 2;
Print("tuttuğun sayı" + tahmin + "bu mu? Daha büyük ise yukarı ok daha küçük ise aşağı ok doğruysa boşluğa bas");
}
}
 

Dosya Ekleri

  • Adsız.png
    69 KB · Görüntüleme: 33
Çözüm

C# dilinde, büyük ve küçük harfler fark yaratır. Sizin kodunuzda olmaması gereken harfler büyük, olmaması gereken harfler küçük. Bu yüzden kodunuz çalışmadı. Birdahakine dikkat edin.

Gözüme gelen bütün hataları düzelttim, ama bu kod ile o attığınız fotoğraftaki kodun alakası yok.


C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Kod : MonoBehaviour {
    int minsayi = 1;
    int maxsayi = 100;
    int tahmin;

    // Start is called before the first frame Update.
    void Start() {
        print("başlatayım mı? (E/H)");
    }

    // Update is called once per frame.
    void Update() {
        if (Input.GetKeyDown(KeyCode.E)) {
            print("1-100 arası bir sayı tut");
        }
        else if (Input.GetKeyDown(KeyCode.H)) {
            print("neden hayır dedin!");
        }
        if (Input.GetKeyDown(KeyCode.Return)) {
            Kontrol();
        }

        if (Input.GetKeyDown(KeyCode.UpArrow)) {
            minsayi = tahmin;
            tahmin = (minsayi + maxsayi) / 2;
            Kontrol();
        }

        if (Input.GetKeyDown(KeyCode.DownArrow)) {
            maxsayi = tahmin;
            Kontrol();
        }
        else if (Input.GetKeyDown(KeyCode.Space)) {
            print("buldum");
        }
    }

    void Kontrol() {
        tahmin = (minsayi + maxsayi) / 2;
        print("tuttuğun sayı " + tahmin + " bu mu? Daha büyük ise yukarı ok, daha küçük ise aşağı ok, doğruysa boşluğa bas");
    }
}

C# dilinde, büyük ve küçük harfler fark yaratır. Sizin kodunuzda olmaması gereken harfler büyük, olmaması gereken harfler küçük. Bu yüzden kodunuz çalışmadı. Birdahakine dikkat edin.

Gözüme gelen bütün hataları düzelttim, ama bu kod ile o attığınız fotoğraftaki kodun alakası yok.


C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Kod : MonoBehaviour {
    int minsayi = 1;
    int maxsayi = 100;
    int tahmin;

    // Start is called before the first frame Update.
    void Start() {
        print("başlatayım mı? (E/H)");
    }

    // Update is called once per frame.
    void Update() {
        if (Input.GetKeyDown(KeyCode.E)) {
            print("1-100 arası bir sayı tut");
        }
        else if (Input.GetKeyDown(KeyCode.H)) {
            print("neden hayır dedin!");
        }
        if (Input.GetKeyDown(KeyCode.Return)) {
            Kontrol();
        }

        if (Input.GetKeyDown(KeyCode.UpArrow)) {
            minsayi = tahmin;
            tahmin = (minsayi + maxsayi) / 2;
            Kontrol();
        }

        if (Input.GetKeyDown(KeyCode.DownArrow)) {
            maxsayi = tahmin;
            Kontrol();
        }
        else if (Input.GetKeyDown(KeyCode.Space)) {
            print("buldum");
        }
    }

    void Kontrol() {
        tahmin = (minsayi + maxsayi) / 2;
        print("tuttuğun sayı " + tahmin + " bu mu? Daha büyük ise yukarı ok, daha küçük ise aşağı ok, doğruysa boşluğa bas");
    }
}
 
Çözüm
sağolun kod çalışıyor ama ekleyemiyorum ve şu hatayı alıyorum
 
Bu siteyi kullanmak için çerezler gereklidir. Siteyi kullanmaya devam etmek için çerezleri kabul etmelisiniz. Daha Fazlasını Öğren.…