C
C#13mo ago
Darkgamer3337

How can i fix this error code?

he's giving me an error code for private?
No description
15 Replies
SinFluxx
SinFluxx13mo ago
What are the lines the errors are referencing? (the error from the sounds of it is pretty clear though)
Darkgamer3337
Darkgamer3337OP13mo ago
No description
Darkgamer3337
Darkgamer3337OP13mo ago
im new so i dont really know how tofix this do you need anything else?
SinFluxx
SinFluxx13mo ago
Can you send the whole class? Also paste is using $code these instructions:
MODiX
MODiX13mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Darkgamer3337
Darkgamer3337OP13mo ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

private float horizontal;
private float speed = 8f;
private float jumpingPower = 16f;
private bool isFacingRight = true;

[SerializeField] private Rigidbody2D rb;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundLayer;


public class player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
horizontal = Input.GetAxisRaw("Horizontal");

if (Input.GetButtonDown("Jump") && IsGroundedGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}

if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}

Flip();
}

private void FixedUpdate()
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
}

private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}

private void Flip()
{
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
isFacingRight = isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
trasform.localScale = localScale;
}
}


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

private float horizontal;
private float speed = 8f;
private float jumpingPower = 16f;
private bool isFacingRight = true;

[SerializeField] private Rigidbody2D rb;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundLayer;


public class player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
horizontal = Input.GetAxisRaw("Horizontal");

if (Input.GetButtonDown("Jump") && IsGroundedGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}

if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}

Flip();
}

private void FixedUpdate()
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
}

private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}

private void Flip()
{
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
isFacingRight = isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
trasform.localScale = localScale;
}
}


}
just a simple script for a 2d character
cap5lut
cap5lut13mo ago
your fields are outside of the player class, thats why u get that error
Darkgamer3337
Darkgamer3337OP13mo ago
now this dosnt work
No description
SinFluxx
SinFluxx13mo ago
You haven't moved them inside your class?
Darkgamer3337
Darkgamer3337OP13mo ago
in the player class?
SinFluxx
SinFluxx13mo ago
yes, like cap5lut said you can't have fields outside of a class
Darkgamer3337
Darkgamer3337OP13mo ago
ok every thing works now, thank you
LordoToasty
LordoToasty13mo ago
hi, I have a .NET proj wich needs help beeing fixed, am I right here?
SinFluxx
SinFluxx13mo ago
@LordoToasty you should create your own thread or ask in #help-0
LordoToasty
LordoToasty13mo ago
I have, thanks.
Want results from more Discord servers?
Add your server