- Home /
Unfixable Assets/Scripts/PlayerAttack.cs(30,15): error CS1525: Unexpected symbol `private'
Assets/Scripts/PlayerAttack.cs(30,15): error CS1525: Unexpected symbol `private' Here is my code, which is where my problem is, and it seems impossible to fix, because everything I have tried, from extra curly braces to different tabs.
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public GameObject target;
public float attackTimer;
public float coolDown;
// Use this for initialization
void Start () {
attackTimer = 0;
coolDown = 2.0f;
}
// Update is called once per frame
void Update () {
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
attackTimer = 0;
if(Input.GetKeyUp(KeyCode.F)) {
if(attackTimer = 0) {
Attack();
attackTimer = coolDown;
}
}
private void Attack(){
float distance = Vector3.Distance(target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
Debug.Log(direction);
if(distance < 2.5f) {
if(direction > 0) {
EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
eh.AddjustCurrentHealth(-10);
}
}
}
}
Answer by rutter · May 23, 2012 at 09:01 PM
The sample code you've posted has unbalanced braces in the Update() function. Looks like you missed a closing brace on one of those if
blocks.
If you're using MonoDevelop, placing the text cursor immediately next to a brace or paren will highlight its opening/closing partner -- this is very handy for spotting problems like this one.
I do not understand what you are saying. I put my cursor over the brace, but nothing happens. I am using $$anonymous$$onoDevelop. If you can, by chance, can you fix the code for me?
Add another } at the end of the Update function, this will fix the error. You should take care of proper indenting, which will help you spot these mistakes: The lines after "if(attackTimer = 0) {" should be indented one level deeper. Also, the statement "if(attackTimer = 0)" in itself is erroneous - it creat at least another compiler warning, if not an error. To compare A to B, use "A==B" - "A=B "is an assignment.
Okay, I did what you said, and it worked, and now I am getting "Cannot implicitly convert type float' to
bool'"
Like they said, this:
if (attackTimer = 0)
Needs to be this:
if (attackTimer == 0)
=
and ==
look similar, but do completely different things.