why am I having issues I would really appreciate the feedback

My Issues:

Assets\Scripts\Player.cs(22,17): error CS1519: Invalid token ‘=’ in class, struct, or interface member declaration
Assets\Scripts\Player.cs(23,8): error CS1519: Invalid token ‘=’ in class, struct, or interface member declaration
Assets\Scripts\Player.cs(23,35): error CS1519: Invalid token ‘(’ in class, struct, or interface member declaration
Assets\Scripts\Player.cs(23,36): error CS8124: Tuple must contain at least two elements.
Assets\Scripts\Player.cs(23,37): error CS1519: Invalid token ‘;’ in class, struct, or interface member declaration
Cannot move asset from Assets/Scripts/TopDownController.cs to Assets/Scripts/Player.cs. Destination path name does already exist
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

My Scripts:

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

public class Player : MonoBehaviour
{
public Camera sceneCamera;

public float moveSpeed;

public Rigidbody2D rb;

public Weapon weapon;

public static float healthAmount;

private Vector2 moveDirection;

private Vector2 mousePosition;

void Start ();
healthAmount = 1;
rb = GetComponent();

// Update is called once per frame
void Update()
{
if (healthAmount <= 0)
Destroy (gameObject);

// Processing Inputs
ProcessInputs();
}

void FixedUpdate()
{
// Physics Calculations
Move();
}

void ProcessInputs()
{
float moveX = Input.GetAxisRaw(“Horizontal”);
float moveY = Input.GetAxisRaw(“Vertical”);

if(Input.GetMouseButtonDown(0))
{
weapon.Fire();
}

moveDirection = new Vector2(moveX, moveY);
mousePosition = sceneCamera.ScreenToWorldPoint(Input.mousePosition);
}

void Move()
{
rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);

// Rotate Player to follow Mouse
Vector2 aimDirection = mousePosition - rb.position;
float aimAngle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg - 90f;
rb.rotation = aimAngle;

void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.name.Equals (“Enemy”))
healthAmount -= 0.1f;
}
}
}

Script 2:

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

public class HealthBar : MonoBehaviour
{
public Vector3 localScale;

// Start is called before the first frame update
void Start()
{
localScale = transform.localScale;
}

// Update is called once per frame
void Update()
{
localScale.x = Player.healthAmount;
transform.localScale = localScale;
}
}

First of all, always use code tags when pasting code snippets

Your code is not formatted correctly,
void Start(); vs

void Start()
{

}

I’m not sure why you changed it. Because you’ve done it correctly in the Update function and in your second script

You don’t need feedback, you need to learn how to read error messages. Fortunately it’s easy. Here’s how:

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly:

Tutorials are a GREAT idea. Tutorials should be used this way:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly. Fortunately this is the easiest part to get right. Be a robot. Don’t make any mistakes. BE PERFECT IN EVERYTHING YOU DO HERE.

If you get any errors, learn how to read the error code and fix it. Google is your friend here. Do NOT continue until you fix the error. The error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

2 Likes

even though I got rid of it, now it wants it there and the other problems still stand
also, can you help me understand what code tags there are? I can’t find one that says code, I can only find ones that say script

I understand it when I look at the code and what I know it’s supposed to do from each line, and I understand the errors for the most part, but sometimes it will ask me to do stuff that I know doesn’t work in the code, what do I do? ps: I actually explained it to myself and then my dog.
I also did look up the problems and couldn’t find a solution
I did folow the tutorial like a robot as well

I’m pretty confident the tutorial never asked you to type this:

And yet it is in the code above.

Maybe that’s your only error, I can’t tell because you neglected to format your code properly.

Now that you have fixed the above, move onto the next error. What is it and what does google tell you about it? What line is it on, what character is it on. You must be able to instantly identify where the compiler is telling you that you made a typo. We can’t do that for you.

It wants me to remove a parentheses that once i remove it wants it and i need, also it wants to get rid of equals signs I need as well
also, can you tell me how I formatted my code wrong? that could possibly be the problem

I already said earlier
void Start(); vs

void Start()
{

}

Which one is correct, earlier you did

void Start ();
healthAmount = 1;
rb = GetComponent<Rigidbody2D>();

Whereas it should be

void Start ()
{
      healthAmount = 1;
      rb = GetComponent<Rigidbody2D>();
}

I already fixed that

And I also tested your script, after fixing that part I get no errors, so I’m not sure what you’ve done

1 Like