many errors

i made this code but there are allot errors in it most seem weird to me i will put the here and the code too if anyone can help me please do:

Assets\scripts\controller\Movement.cs(52,21): error CS1026: ) expected

Assets\scripts\controller\Movement.cs(52,21): error CS1525: Invalid expression term ‘,’

Assets\scripts\controller\Movement.cs(52,21): error CS1002: ; expected

Assets\scripts\controller\Movement.cs(52,21): error CS1513: } expected

Assets\scripts\controller\Movement.cs(52,48): error CS1002: ; expected

Assets\scripts\controller\Movement.cs(52,48): error CS1513: } expected

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

public class Movement : MonoBehaviour
{
    float Speed;

    public Rigidbody rb;
    public bool PlayerOnGround = true;

    private void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
    // Start is called before the first frame update
    void Start()
    {
        Speed = 5;
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * Speed, 0, Input.GetAxis("Vertical") * Time.deltaTime * Speed);

        if(Input.GetKey(KeyCode.UpArrow)) {
            transform.Translate(5, 0, 10 * Time.deltaTime);
        }
        if(Input.GetKey(KeyCode.DownArrow)) {
            transform.Translate(5, 0, -10 * Time.deltaTime);
        }
        if(Input.GetKey(KeyCode.LeftArrow)) {
            transform.Translate(-10 * Time.deltaTime, 0, 0);
        }
        if(Input.GetKey(KeyCode.RightArrow)) {
            transform.Translate(10 * Time.deltaTime, 0, 0);
        }
        if(Input.GetButtonDown("w")(Input.GetButtonDown("w" + "left shift"))) {
            transform.Translate(10 * Time.deltaTime * 3f, 0, 0);
        }
       
        if(Input.GetButtonDown("jump") && PlayerOnGround)
        {
            rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
            PlayerOnGround = false;
        }
    }

    private void onCollisionEnter(Collision collision)
    {
        if(collision,gameobject.tag == "ground")
        {
            PlayerOnGround = true;
        }
    }
}

[code]

Please re-add the code example using code tags. This adds syntax highlighting and allows for proper indentations. There are probably a couple missing brackets somewhere, but as it is now it’s hard to spot.

One thing for now GetButtonDown(“w” + “left shift”) is not a thing. You’d rather check for GetButton(KeyCode.LeftShift) and inside that you check for GetButtonDown(KeyCode.W).

Edit: One more thing i just noticed, all the way down you write collision,gameobject.tag. The comma there is responsible for at least one error, it got to be a dot. And gameobject does not exist, it’s gameObject instead. Programming is case sensitive, you cant just write things down “somewhat similar” and expect them to work :slight_smile:

1 Like

line 60 is on accident

Ok, so maybe i worded that a bit badly. But the Input check for two keys should look like this:

if(Input.GetKey(KeyCode.LeftShift)){ // <-- note how this is GetKey
    if(Input.GetKeyDown(KeyCode.W)){ // <-- and this GetKeyDown
       // Do stuff supposed to happen when LShift + W is pressed once
    }
}

Afterwards (some mentioned above in my edit):

  • line 53: the comma needs to be a dot
  • line 53: gameobject needs to be gameObject
  • line 51: onCollisionEnter does not exist, OnCollisionEnter does. Currently you are declaring your own new onCollisionEnter method, which is fine, but wont be called by Unity, which you intend.

This the above and then let’s see the updated code and the new / remaining error messages :slight_smile:

this is the new code (if i got it right) and errors:

Assets\scripts\controller\Movement.cs(17,10): error CS0111: Type ‘Movement’ already defines a member called ‘Start’ with the same parameter types

Assets\RagdollDeath.cs(8,6): error CS0246: The type or namespace name ‘SerializedFieldAttribute’ could not be found (are you missing a using directive or an assembly reference?)

Assets\RagdollDeath.cs(8,6): error CS0246: The type or namespace name ‘SerializedField’ could not be found (are you missing a using directive or an assembly reference?)

Assets\scripts\RagdollDeath.cs(8,2): error CS0246: The type or namespace name ‘SerializedFieldAttribute’ could not be found (are you missing a using directive or an assembly reference?)

Assets\scripts\RagdollDeath.cs(8,2): error CS0246: The type or namespace name ‘SerializedField’ could not be found (are you missing a using directive or an assembly reference?)

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

public class Movement : MonoBehaviour
{
    float Speed;

    public Rigidbody rb;
    public bool PlayerOnGround = true;

    private void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
    // Start is called before the first frame update
    void Start()
    {
        Speed = 5;
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * Speed, 0, Input.GetAxis("Vertical") * Time.deltaTime * Speed);

        if(Input.GetKey(KeyCode.UpArrow)) {
            transform.Translate(5, 0, 10 * Time.deltaTime);
        }
        if(Input.GetKey(KeyCode.DownArrow)) {
            transform.Translate(5, 0, -10 * Time.deltaTime);
        }
        if(Input.GetKey(KeyCode.LeftArrow)) {
            transform.Translate(-10 * Time.deltaTime, 0, 0);
        }
        if(Input.GetKey(KeyCode.RightArrow)) {
            transform.Translate(10 * Time.deltaTime, 0, 0);
        }
        if(Input.GetButtonDown("w")) {
            if(Input.GetButtonDown("left shift")){
                transform.Translate(10 * Time.deltaTime * 3f, 0, 0);
            }
           
        }
       
        if(Input.GetButtonDown("jump") && PlayerOnGround)
        {
            rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
            PlayerOnGround = false;
        }
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(collisionn.gameObject.tag == "ground")
        {
            PlayerOnGround = true;
        }
    }
}

[code]

and thank you i real appreciate it

if you are allready helping me can you see this code and tell me what the errors mean:

Assets\scripts\RagdollDeath.cs(33,14): error CS0111: Type ‘RagdollDeath’ already defines a member called ‘ToggleRagdoll’ with the same parameter types

Assets\scripts\RagdollDeath.cs(23,14): error CS0111: Type ‘RagdollDeath’ already defines a member called ‘Die’ with the same parameter types

Assets\scripts\RagdollDeath.cs(13,14): error CS0111: Type ‘RagdollDeath’ already defines a member called ‘Start’ with the same parameter types

Assets\scripts\RagdollDeath.cs(23,14): error CS0111: Type ‘RagdollDeath’ already defines a member called ‘Die’ with the same parameter types

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

public class RagdollDeath : MonoBehaviour
{
[Header("References")]
[SerializedField] private Animator animator = null;

private Rigidbody[] ragdollBodies;
private Collider[] ragdollColloders;

private void Start()
{
ragdollBodies = GetComponentsInChildren<Rigidbody>();
ragdollColliders = GetComponentsInChildren<Collider>();

ToggleRagdoll(False);

Invoke(nameof(Die), 5f);
}

private void Die()
{
ToggleRagdoll(true);

foreach(Rigidbody rb in ragdollBodies)
{
rb.AddExplosionForce(107f, new Vector3(-1f, 0.5f, -1f), 5f, 0f, ForceMode.Impulse);
}
}

private void ToggleRagdoll(bool state)
{
animator.enabled = !state;

foreach(Rigidbody rb in ragdollBodies)
{
rb.isKinematic = !state;
}

foreach (Collider collider in ragdollColliders)
{
collider.enavled = state;
}
}


}

[code]

The error message is pretty much telling you what is wrong. The type “Movement” which you defined, already has a “Start()” function. Meaning you got two. At line 13 and 18. You cant have the same method twice.

If the compiler tells you that it can not find something, then it’s either not imported, or you included a typo. In this case (and oftentimes for beginners, so double check!) it’s the latter.
https://docs.unity3d.com/ScriptReference/SerializeField.html
“SerializeField” not “SerializedField” :slight_smile:

As for the other errors in the RagdollDeath script, they may be follow-errors by the already confused compiler. They imply that you got stuff twice again, which you dont. So fix the above first and then check if these errors still exist.
On that note tho, line 45 in your RagdollDeath script you write collider.enavled which does not exist. You mean enabled. Try to avoid typos like these. They are easy to spot but can be pretty irritating when getting started.

i only have this error in the movement script and i dont know what it means.
and again thank you for the help

Assets\scripts\controller\Movement.cs(17,10): error CS0111: Type ‘Movement’ already defines a member called ‘Start’ with the same parameter types

Please read the first thing i wrote to you in my last reply. It adresses exactly that error.

like yoreki said, you can just read the error, it tells you what is wrong and on which line of your code

you can double click the error on the console and it will open your code editor on the exact spot of the error

what can i do about it?