Getting this error; Member modifier 'public' must percede member type and details. Why?
Hi everybody! This is my first time here. I'm making a movement script using this guide; https://www.youtube.com/watch?v=QGDeafTx5ug. I'm implementing combat using the Bandit asset, and am using Brackey's melee combat tutorial: https://www.youtube.com/watch?v=sPiVz1k-fEs. This is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour { Transform attackPoint;
public int maxHealth = 100;
private currentHealth
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public float speed;
public Animator animator;
public float jumpForce;
private float moveInput;
private Rigidbody2D rb;
private bool facingRight = true;
private bool isGrounded;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatIsGround;
private int extraJumps;
public int extraJumpsValue;
public currentHealth Public1 { get => Public; set => Public = value; }
void Start()
{
currentHealth = maxHealth;
extraJumps = extraJumpsValue;
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (facingRight == false && moveInput > 0)
{
Flip();
} else if (facingRight == true && moveInput < 0)
{
Flip();
}
}
public void TakeDamage(int damage)
{
currentHealth -= damage;
if(currentHealth <= 0)
{
Die();
}
}
void Die()
{
Debug.Log("Somebody died!");
}
void Update()
{
if(isGrounded == true)
{
extraJumps = extraJumpsValue;
}
if(Input.GetKeyDown(KeyCode.Space))
{
Attack();
}
if(Input.GetKeyDown(KeyCode.UpArrow ) && extraJumps > 0)
{
rb.velocity = Vector2.up * jumpForce;
extraJumps--;
} else if(Input.GetKeyDown(KeyCode.UpArrow) && extraJumps == 0 && isGrounded == true)
{
rb.velocity = Vector2.up * jumpForce;
}
animator.SetFloat("Speed", Mathf.Abs(moveInput));
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
void Attack()
{
//Play attack anim
animator.SetTrigger("Attack");
//Detect enemies in range of attack
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, AttackRange, enemyLayers);
//Damage them, of course!
foreach(Collider2D enemy in hitEnemies)
{
Debug.Log("We hit" + enemy.name);
}
}
void OnDrawGizmosSelected()
{
if(attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, AttackRange);
}
}
Unity is flagging up an error with the "public float attackRange" line. It says that the the public modifier must precede the member type and name. Does anyone know how to fix this? And also I know that the script is one huge mess, but when I tried to seperate the movement and combat in 2 seperate scripts, I got different errors and found that mashing the two scripts into one fixed those errors. When i reloaded Unity the next day, it said thay my void Start() line was invalid, even though I hadn't touched it except for those three lines of code. But now that error is gone (I didn't do anything) and has been replaced by the "public not valid" error. Any help?
Your answer
![](https://koobas.hobune.stream/wayback/20220612230329im_/https://answers.unity.com/themes/thub/images/avi.jpg)