I have attached a file that has my script. Please tell me whats wrong and if possible please send me a proper code. Thanks you
using UnityEngine;
using System.Collections;
public class playercontroller : MonoBehaviour {
public float moveSpeed;
public float jumpHeight;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Space))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(0, jumpHeight)
}
}
those errors will help you debug the code. Parse errors are usually caused by misplaced/missing semi-colons, braces, brackets etc. Start by clicking on the very last } in your script & see what opposite one is highlighted. It should be the very first one in your script. Work your way through it until all your {} are aligned & matched correctly then try your script again. If you have other errors then see what the message is telling you (it usually gives the line the problem is with or double click the message & it will take you to the line that caused the error (it may not be the line where the actual error is though)) & work through it again.
No, you need to learn or you will get stuck again with your next script. Debugging is something everyone has to do.
I also don’t open attachments, especially google drive as last time I did someone tried to hack my google account as it was a fake document login page.
You can post the code in here by using the code tags
i have in total 3 codes and all have the error, no monobehaviour script in them. i dont know how to post it and btw im only 13 years old and am new to coding
This is the code i was talking about, i have 2 more which have the same error (no monobehaviour script or name of file does not match)
using UnityEngine;
using System.Collections;
public class playercontroller : MonoBehaviour {
public float moveSpeed;
public float jumpHeight;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Space))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(0, jumpHeight)
}
}
}
If you post something here you are expected to post the code and make sure you use code tags so we can read it right here without needing to download anything. People don’t mind helping, but they aren’t going to download random files to help you.
For syntax errors like this and null reference exceptions you should not post them here. These sorts of errors basically tell us that you need to go learn the basics on your own.
It does not matter if you are 13, you’re posting here and still get the same treatment and respect as everyone else both young and old however you are expected to act like an adult here.
The only attachment/code appears to be the google drive one in The first post, there’s no other post.
Compare your code to the tutorial. The missing monobehaviour could be the formatting (incorrect {} or other error) or incorrect naming.
If you are doing the tutorial go over it all again to double check you haven’t missed anything or made a typo. Formatting & syntax are very important before you even get onto the more complex concepts & reviewing your code is something you will be doing over & over again as no ones code ever works perfectly the first time.
i have checked it multiple times and i cant find anything. You look very experienced, cant you just quickly go through the code and see whats wrong cuz i cant.
You’re likely to get one more friendly version of the message before someone tells you harshly.
The whole point of a tutorial is to learn. If you run to the forum at the first sign of trouble and ask – borderline demand, really – that others figure out your issues, what have you actually learned?
As Ted said, the errors you’re seeing will point you to exactly where the problem is. If you don’t know what the messages mean, Google them. I promise you that anything you’ll run into at this stage has been asked and answered a thousand times before across the Internet. If you don’t know how to properly Google things, you’ll truly be lost forever.
You also don’t seem to listen. We’re not interested in downloading your code file and opening it ourselves. Follow the forum rules, and copy-paste your code into a code tag in a post. Then we’ll look at it. The way you’ve shared your code is not an acceptable way of offering us anything.
Even once you do post your code properly, we likely could just tell you how to change it to make it work, but what will that gain you? Will you suddenly feel comfortable tackling things on your own from that point on?
I totally get it. You’re young and impatient and want to sprint without having to go through the boring crawl phase. But if you can’t solve simple problems like this, you have no chance of actually going anywhere with your game development. It’s a ton of hard work, despite what you hear.