For some reason, error codes listed in the title of the post appeared in a movement script I was designing, and even after removing the causes of the errors, new ones popped in its place. I attempted brute forcing it but it didn’t work.
Here’s the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float movementSpeed = 3.0f;
Vector2 movement = new Vector2();
Rigidbody2D = rb2D
private void Start()
{
rb2D = GetComponent();
}
private void Update()
{
//Temporalily empty, more will be added soon, as this is the framework.
}
When you post code, put it in code tags. It’s literally the second sticky post in the scripting forum that explains how
We don’t care or remember error codes. Errors have a human readable english description that is quite clear.
When you get errors, you usually get a line and even column number telling you exactly where the error occured. You get this information for free. So when you need help solving YOUR errors, at least share this information.
The actual error is either in the line that the compiler complains about, or above as the compiler also reads your code top to bottom, left to right. You seem to messed up your “rb2D” declaration big time. You’re missing a semicolon at the end and also have an equals sign that makes no sense. I would tell you the line number, if your code was actually posted in a code block.
ps: When you edit your post, please make sure you copy your original code. Missing code formattingi usually messes up the formatting and can even alter some of the code as it’s mis interpreted.
C# doesn’t tend to be very good at determining some kinds of errors, and if you have multiple errors on the same line it can become confused. The line where you define the Rigidbody2D field is the problem in the posted code.
Can anyone tell me what is wrong with this? I get an error 1585: Member modifier ‘Private’ must precede the member type and name. What do I have to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum HealType
{
Direct,
Explosion
}
public class HealthPickup : MonoBehaviour
{
private PlayerHealth
private HealType healType = HealType.Direct; // The Heal type - Direct applys Heal directly from the projectile, Explosion lets an instantiated explosion handle Heal
public float Heal = 100.0f; // The amount of Heal to be applied (only for Direct Heal type)
public static float currentHealth = playerHealth.currentHealth;
public static float currentArmor = playerHealth.currentArmor;
void Awake()
{
playerHealth = GetComponent<PlayerHealth>();
}
void OnCollisionEnter(Collision col)
{
// If the projectile collides with something, call the Hit() function
Hit(col);
}
void Hit(Collision col)
{
if (PlayerHealth.currentHealth < PlayerHealth.maxHealth)
{
// Apply Heal to the hit object if HealType is set to Direct
if (healType == HealType.Direct)
{
col.collider.gameObject.SendMessageUpwards("ChangeHealth", +Heal, SendMessageOptions.DontRequireReceiver);
Destroy(gameObject);
//call the ApplyHeal() function on the enenmy CharacterSetup script
if (col.collider.gameObject.layer == LayerMask.NameToLayer("Limb"))
{
Vector3 directionShot = col.collider.transform.position - transform.position;
// Un-comment the following section for Bloody Mess support
/*
if (col.collider.gameObject.GetComponent<Limb>())
{
GameObject parent = col.collider.gameObject.GetComponent<Limb>().parent;
CharacterSetup character = parent.GetComponent<CharacterSetup>();
character.ApplyHeal(Heal, col.collider.gameObject, weaponType, directionShot, Camera.main.transform.position);
}
*/
}
}
}
}
}
Please in the future, do not hijack other people’s threads, especially when they are that old. When different people bring different code with problems the thread becomes a mess. When you have a problem, create a new thread.
Your line 14 makes no sense because
It lookse like half of a variable declaration, but your missing the variable name
That line is not terminated with a semicolon. That’s why the compiler complains about the “private” in the next line.
Keep in mind that the compiler does not care about new lines with a few exceptions (one are line comments which terminate with a new line). Other than that you could write your whole script in a single line. So your code currently reads this: