New to this missing ","?

This is my code. It’s supposed to load a new scene when the player touches a cube but it has these errors.
"
Assets\Level Finish.cs(4,19): error CS1002: ; expected
Assets\Level Finish.cs(4,19): error CS0116: A namespace cannot directly contain members such as fields or methods
Assets\Level Finish.cs(4,31): error CS1022: Type or namespace definition, or end-of-file expected
Assets\Level Finish.cs(6,37): error CS1001: Identifier expected
Assets\Level Finish.cs(6,37): error CS1003: Syntax error, ‘,’ expected
Assets\Level Finish.cs(6,39): error CS1003: Syntax error, ‘,’ expected
Assets\Level Finish.cs(6,47): error CS1001: Identifier expected
"
This is probably very obvious but I just started with C# so… Thanks

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

function OnTriggerEnter(CollabProxy : Collider)
{
    if(CollabProxy.tag == "Player")
    {
        Application.LoadLevel(Application.loadedLevel + 1);
    }
}

You lost that little dot inbetween. Here it is:

using UnityEngine.SceneManager;

Also, parameter declaration order is reversed and : is not needed

function OnTriggerEnter(Collider CollabProxy)

I recommend you Jeffrey Richter book on C#/.NET. My personal favorite.

You are also missing a class declaration. It looks like you have tried to copy code from Unityscript and C#.

1 Like

Thank you!!

You’re probably right. How do I fix it? I now have these
"
Assets\LevelFinish.cs(6,10): error CS0116: A namespace cannot directly contain members such as fields or methods
Assets\LevelFinish.cs(6,1): error CS0246: The type or namespace name ‘function’ could not be found (are you missing a using directive or an assembly reference?)
"

This line:

function OnTriggerEnter(CollabProxy : Collider)

Is actually not C#. That’s the main problem you have. It looks like you may have copy and pasted code from a UnityScript listing. UnityScript is an old programming language that Unity no longer supports. Fortunately, it’s similar to C# so it’s not difficult to convert.

That line above should be:

void OnTriggerEnter (Collider CollabProxy)

Also, C# methods and variables always need to be inside of a class definition. To see an example class definition, try creating a “new C# script” in the project window. Unity will create a default C# script with a class definition inside. When you open it, you’ll see where it says something like public class ScriptName:MonoBehaviour ScriptName is where the class name should go, so replace that with the name of the class. You basically need to create a similar class definition for your own code.

Notice that there is “{” after that line and another “}” at the end of the file. In C#, these symbols are used to indicate the beginning and end of class, or a function, or a code block. It’s important that everything in your class is inside of these { } curly brackets.

The Update and Start functions are optional. You don’t need those.

By the way, In Unity, the name of the class in your class definition must always be the same as the script’s filename (That’s a Unity rule, not a C# rule). In your case, your file is called “Level Finish.cs”, but in C#, class names cannot have spaces in them, so you’ll have to change the name to “LevelFinish.cs”.

All of this is explained in more detail here:

You need to declare a class. Also, C# uses a return type on methods. In this case, you do not need to return anything so it would be void.

using UnityEngine;
using UnityEngine.SceneManagement;

public class MyClass : MonoBehaviour
{
    private void OnTriggerEnter(Collider collider)
    {
        if (collider.tag == "Player")
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
        }
    }
}
1 Like

i have the same error too how do i fix it help pls

Don’t hijack a one±year old script for what is essentially a new question.

I recommend making a new question, and here are some tips on how to report an issue:

http://plbm.com/?p=220

1 Like

help i get ‘,’ expected

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public int i == 0f;
public Text ScoreCount;
void Update()
{
while(i <= 99)
{
StartCoroutine(scoreManager());
i++;
}

ScoreCount.text == i;
}
IEnumerator scoreManager()
{
yield return new WaitForSeconds(1);
}
}

Start your own post instead of replying to the first thread that comes up on google.
When you do, post using code tags, and copy and paste the full error message instead of summarizing it.

At a glance though I can see that you’re using == where you should be using =. One equals sign is assignment, two equals signs are comparison (for use in “if” statements).

2 Likes

thanks

est ce que vous pouvez m’aider svp mon code m affiche erreur CS1003

this is my code
classe publique TankHealth: MonoBehaviour;
{
flotteur public m_StartingHealth = 100f; // La quantité de santé avec laquelle chaque tank commence.
public Slider m_Slider; // Le curseur pour représenter la santé du réservoir actuellement.
Image publique m_FillImage; // Le composant image du curseur.
public Color m_FullHealthColor = Color.green; // La couleur de la barre de santé sera en pleine santé.
public Color m_ZeroHealthColor = Color.red; // La couleur de la barre de santé sera en cas d’absence de santé.
public GameObject m_ExplosionPrefab; // Un préfabriqué qui sera instancié dans Awake, puis utilisé chaque fois que le tank meurt.

AudioSource privé m_ExplosionAudio; // La source audio à jouer lorsque le tank explose.
Private ParticleSystem m_ExplosionParticles; // Le système de particules jouera lorsque le tank sera détruit.
flotteur privé m_CurrentHealth; // De combien de santé le tank a actuellement.
booléen privé m_Dead; // Le tank a-t-il encore été réduit au-delà de zéro santé?

privé vide Awake ()
{
// Instanciez le préfabriqué d’explosion et obtenez une référence au système de particules dessus.
m_ExplosionParticles = Instancier (m_ExplosionPrefab) .GetComponent ();

// Récupère une référence à la source audio sur le préfabriqué instancié.
m_ExplosionAudio = m_ExplosionParticles.GetComponent ();

// Désactivez le préfabriqué pour qu’il puisse être activé quand c’est nécessaire.
m_ExplosionParticles.gameObject.SetActive (faux);
}

private void OnEnable ()
{
// Lorsque le réservoir est activé, réinitialisez la santé du réservoir et s’il est mort ou non.
m_CurrentHealth = m_StartingHealth;
m_Dead = faux;

// Mettre à jour la valeur et la couleur du curseur de santé.
SetHealthUI ();
}

public void TakeDamage (montant flottant)
{
// Réduit la santé actuelle du montant des dégâts infligés.
m_CurrentHealth - = montant;

// Modifiez les éléments de l’interface utilisateur de manière appropriée.
SetHealthUI ();

// Si l’état de santé actuel est égal ou inférieur à zéro et qu’il n’a pas encore été enregistré, appelez OnDeath.
si (m_CurrentHealth <= 0f &&! m_Dead)
{
OnDeath ();
}
}

private void SetHealthUI ()
{
// Définit la valeur du curseur de manière appropriée.
m_Slider.value = m_CurrentHealth;

// Interpole la couleur de la barre entre les couleurs choisies en fonction du pourcentage actuel de la santé de départ.
m_FillImage.color = Color.Lerp (m_ZeroHealthColor, m_FullHealthColor, m_CurrentHealth / m_StartingHealth);
}

private void OnDeath ()
{
// Définit le drapeau pour que cette fonction ne soit appelée qu’une seule fois.
m_Dead = vrai;

// Déplacez le préfabriqué d’explosion instancié vers la position du réservoir et activez-le.
m_ExplosionParticles.transform.position = transform.position;
m_ExplosionParticles.gameObject.SetActive (vrai);

// Joue le système de particules du réservoir qui explose.
m_ExplosionParticles.Play ();

// Joue l’effet sonore de l’explosion du réservoir.
m_ExplosionAudio.Play ();

// Éteignez le réservoir.
gameObject.SetActive (faux);
}
}

Looks like you pasted a C# script in Google translate. That’s not valid C# at all. Please look up a basic C# tutorial.

1 Like

plz help

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

public class Arms : MonoBehaviour
{
int speed = 3000;
public Rigidbody2D rb;
public Camera cam;
public KeyCode mousebutton;

void Update()
{
Vector3 playerpos = new Vector3(cam.ScreenToWorldPoint(Input.mousePosition).x,cam.ScreenToWorldPoint(Input.mousePosition).y 0);
Vector3 difference = playerpos - transform.position;
float rotationZ = Mathf.Atan2(difference.x, -difference.y) * Mathf.Rad2Deg;
if (Input.GetKey(mousebutton))
{
rb.MoveRotation(Mathf.LerpAngle(rb.rotation, rotationZ, speed * Time.fixedDeltaTime));
}
}
}

You didn’t even read any of the content of this thread, right? It’s the same thing again: Don’t try to hijack an ancient thread, create your own thread. When you do, put some efford into your thread by explaining what you want to do, what doesn’t work or what you want to know. Finally when posting code, use code tags.

So do I also need to start a new thread? My error is below:

Assets\Scripts\SupersonicEvents.cs(66,51): error CS1003: Syntax error, ‘,’ expected
Assets\Scripts\SupersonicEvents.cs(67,66): error CS1003: Syntax error, ‘,’ expected

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

public class SupersonicEvents : MonoBehaviour
{
    void OnEnable()
    {
        SupersonicEvents.onOfferwallInitSuccessEvent += OfferwallInitSuccessEvent;
 
        SupersonicEvents.onOfferwallInitFailEvent += OfferwallInitFailEvent;
 
        SupersonicEvents.onOfferwallOpenedEvent += OfferwallOpenedEvent;
 
        SupersonicEvents.onOfferwallAdCreditedEvent += OfferwallAdCreditedEvent;
 
        SupersonicEvents.onOfferwallClosedEvent += OfferwallClosedEvent;
 
        SupersonicEvents.onOfferwallShowFailEvent += OfferwallShowFailEvent;
 
        SupersonicEvents.onGetOfferwallCreditsFailEvent += GetOfferwallCreditsFailEvent;
    }
   
   
    void OnDisable()
    {
        SupersonicEvents.onOfferwallInitSuccessEvent -= OfferwallInitSuccessEvent;
 
        SupersonicEvents.onOfferwallInitFailEvent -= OfferwallInitFailEvent;
 
        SupersonicEvents.onOfferwallOpenedEvent -= OfferwallOpenedEvent;
 
        SupersonicEvents.onOfferwallAdCreditedEvent -= OfferwallAdCreditedEvent;
 
        SupersonicEvents.onOfferwallClosedEvent -= OfferwallClosedEvent;
 
        SupersonicEvents.onOfferwallShowFailEvent -= OfferwallShowFailEvent;
 
        SupersonicEvents.onGetOfferwallCreditsFailEvent -= GetOfferwallCreditsFailEvent;
 
    }
   
   
        /**
        * Invoked when the Offerwall is prepared an ready to be shown to the user
        */
        void OfferwallInitSuccessEvent();
        /**
        * Invoked when the Offerwall does not load for the user
        */
        void OfferwallInitFailEvent(SupersonicError error);
        /**
        * Invoked when the Offerwall successfully loads for the user.
        */
        void OfferwallOpenedEvent();
        /**
        * Invoked when the method 'showOfferWall' is called and the OfferWall fails to load.  //@param desc - A string which represents the reason of 'showOfferwall' failure.
        */
        void OfferwallShowFailEvent(SupersonicError error);
        /**
        * Invoked each time the user completes an Offer.
        * Award the user with the credit amount corresponding to the value of the ‘credits’
        * parameter.
        * @param dict - A dictionary which holds the credits and the total credits.  
        */
        void OfferwallAdCreditedEvent(Dictionary<string object> dict){
        Debug.Log ("I got OfferwallAdCreditedEvent, current credits = "dict["credits"] + "totalCredits = " + dict["totalCredits"]);
        }
        /**
        * Invoked when the method 'getOfferWallCredits' fails to retrieve
        * the user's credit balance info.
        * @param desc - A string object which represents the reason of 'getOffereallCredits' failure.
        */
        void GetOfferwallCreditsFailEvent(SupersonicError error);
        /**
        * Invoked when the user is about to return to the application after closing
        * the Offerwall.
        */
        void OfferwallClosedEvent();
}

I talked about a forum thread, not about code -.-. You just did the same thing as aizathossain did. You just bumped an unrelated thread with your own question. If you have a question, just create your own seperate post.

1 Like

I also have the same error message of - …“,” - which is why I added my code here as it is relevant to the thread which is Syntax error, ‘,’ expected. So I don’t understand why I have to create a new thread.