Unity ошибка cs1003

Ошибка в коде
error CS1003: Syntax error, ‘,’ expected
Как исправить ?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelController : MonoBehaviour
{
        public Button Level2;
        public Button Level3;
        public Button Level4;
        int levelComplete;


    void Start()
    {
        levelComplete = PlayerPrefs.GetInt("LevelComplete");
        Level2.interactable = false;
        Level3.interactable = false;


        switch (levelComplete)
        {
            case 1:
                Level2.interactable = true;
                break;
            case 2:
                Level2.interactable = true;
                Level3.interactable = true;
                break;
        }
    }

    public void LoadTo(int level)
    {
        SceneManager.LoadScene(Round Selection);
    }
}

задан 5 янв 2021 в 15:31

Sanchek19's user avatar

3

Метод LoadScene принимает в себя в качестве первого параметра или int (sceneBuildIndex) или string (sceneName).

Ваш Round Selection не то и не другое, но вот если завернуть его в кавычки: "Round Selection", то в всё должно заработать.

ответ дан 5 янв 2021 в 15:40

Sergey Skvortsov's user avatar

Skip to content

I am recreating Flappy bird as my first project in unity (version 2021.3.6f1). I’m using Visual Studio to compile the C# script.

I get error CS1003 ‘,’ expected on (8,42)

My Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public Rigidbody2D rb;
    public FlightForce = new Vector2(0f, 10f);

    // Update is called once per frame
    void Update()
    {
    
        if (Input.GetKeyDown("space"))
        {

            rb.AddForce(FlightForce, ForceMode2D.Force);

        }

    }
}

>Solution :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public Rigidbody2D rb;
    public FlightForce = new Vector2(0f, 10f); // <--- you didn't provide the type here

    // Update is called once per frame
    void Update()
    {
    
        if (Input.GetKeyDown("space"))
        {

            rb.AddForce(FlightForce, ForceMode2D.Force);

        }

    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlaerMufment : MonoBehaviour {

    CharacterController cc;
    Vector3 moveVec;

    float speed = 5;

    int laneNamber = 1,
        lanesCount = 2;

    public float FirstlanePos,
                 LaneDistance,
                 SideSpeed;


    void Start()
    {
        cc = GetComponent<CharacterController>();
        moveVec = new Vector3(1, 0, 0);
    }

    


    void Update()
    {
        moveVec.x *= speed;
        moveVec *= Time.deltaTime;

        float imput = Input.GetAxis("Horizontal");

        if (Mathf.Abs(input) >.if);
        {
            laneNamber += (int)Matht.Sign(input);
            laneNamber = Mathf.Clamp(laneNamber, 0, lanesCount);
        }

        Vectore3 newPos = transfore.position;
        newPos.z = Mathf.Lerp(newPos.z, FirstLanePos + (laneNamber * LaneDistance), Time.deltaTime * SideSpeed);
        transform.position = newPos;

        cc.Move(moveVec);
    }
}

AssetsSkriptPlaerMufment.cs(36,31): error CS1525: Invalid expression term ‘.’
AssetsSkriptPlaerMufment.cs(36,32): error CS1001: Identifier expected
AssetsSkriptPlaerMufment.cs(36,32): error CS1026: ) expected
AssetsSkriptPlaerMufment.cs(36,34): error CS1003: Syntax error, ‘(‘ expected
AssetsSkriptPlaerMufment.cs(36,34): error CS1525: Invalid expression term ‘)’

aboba11235, ты скинул совсем не рабочий код. Это лишь одна из ошибок, которая ждала бы тебя в будущем.
Его даже исправить нельзя. Его нужно просто переделать. Я просто укажу на ошибки.

1) Почитай документацию к GUI.Label: https://docs.unity3d.com/Scrip… Label.html
2)

Цитата
Сообщение от aboba11235
Посмотреть сообщение

public GameObject Player;

public не нужен, если ты ищешь объект внутри этого же кода (строка 14)
3)

Цитата
Сообщение от aboba11235
Посмотреть сообщение

void OnColliderEnter (Collider other)

Такого метода нет. Есть OnCollisionEnter и его параметр должен быть типа Collision.
4)

Цитата
Сообщение от aboba11235
Посмотреть сообщение

if (Input.GetKeyDown(KeyCode.Mouse0))

Отработка нажатий должна вызываться каждый кадр, а метод OnCollisionEnter вызывается единожды при касании. (Скорее всего стоит заменить на OnCollisionStay)
5)

Цитата
Сообщение от aboba11235
Посмотреть сообщение

Player.GetComponent<Score>().Score += 10;

Ты назвал переменную так же, как и класс? Опрометчивое решение. Будут ошибки. Пофантазируй на эту тему.
6)

Цитата
Сообщение от aboba11235
Посмотреть сообщение

GUI.Label(new Rect(10, 10, 100, 100), «Score: » Score);

А теперь главная ошибка. И она вытекает из пункта 5. Компилятор думает, что ты пытаешься туда засунуть класс Score, а классы со строкой не совещаются, какое горе. Тебе нужна переменная Score в скрипте Score? Тогда обращайся к классу Score и его полю Score (согласно пункту 5 её стоит переименовать).

Если вдруг ещё останутся вопросы, задавай.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    public string firstName;
    public string lastName;
    public int birthYear;
    // Start is called before the first frame update
    void Start()
    {
        print("Your first name is : " + firstName + "and your last name is " + lastName);
        print("Your initials are: " firstName[0] + lastName[0]);
        print("The lenght of your full name is " (firstName + lastName).Length);
        int Age = 2018 - birthYear;
        print("Your age is :" + Age.ToString );
        int dayAlive = Age * 365;
        print("You lived: " dayAlive.ToString "days");
    }

    // Update is called once per frame
    void Update()
    {        
    }

This is a code I made following a tutorial (few simple problems to get an understanding of the basics)

And I keep getting these errors:

Severity Code Description Project File Line Suppression State

Error CS1003 Syntax error, ‘,’ expected Miscellaneous Files 14 Active

Error CS1003 Syntax error, ‘,’ expected Miscellaneous Files 19 Active

Error CS1003 Syntax error, ‘,’ expected Miscellaneous Files 19 Active

Can someone please help me??

Понравилась статья? Поделить с друзьями:
  • Unity ошибка cs0234
  • Unity ошибка cs0101
  • Unity ошибка 0246
  • Unity выдает ошибку при установке
  • Unity выдает ошибку при запуске игры