- Home /
Unexpected symbol error
I get this error message:
Assets/enemyAI.cs(48,2): error CS1001: Unexpected symbol `}', expecting identifier
from this piece of code:
void Update()
{
attacktimer += (1 * Time.deltaTime);
patrolTimer += (1 * Time.deltaTime);
if (attacking != true)
{
if (targetPoint != null)
{
Vector3 dir = targetPoint.position - transform.position;
dir.z = 0.0f;
if (dir != Vector3.zero)
{
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.FromToRotation (Vector3.right, dir), rotationSpeed * Time.deltaTime);
}
transform.position += (targetPoint.position - transform.position).normalized * moveSpeed * Time.deltaTime;
}
rb2d.velocity = Vector3.zero;
}
else
{
if (target != null)
{
Vector3 dir = target.position - transform.position;
dir.z = 0.0f;
if (dir != Vector3.zero)
{
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.FromToRotation (Vector3.right, dir), rotationSpeed * Time.deltaTime);
}
transform.position += (target.position - transform.position).normalized * moveSpeed * Time.deltaTime;
}
rb2d.velocity = Vector3.zero;
}
if (patrolTimer > switchTime)
{
targetPoint = currentPoint.GetComponent<movePointScript> ().GetPoint ();
patrolTimer = 0.0f;
}
}
when I click on the message it takes me to the } above the first else statement (line 20 above)
the solution is probably something small I'm missing since I haven't used unity in a while.
Thanks
Rigidbody.velocity is a Vector2, not Vector3. But I doubt this is the problem. I don't see any problem the code you shared.
Assets/enemyAI.cs(48,2): but you only show us 42 lines of code. Pls edit Q to include the whole file. The fact that it references line 48, makes me think perhaps the issue is OUTSIDE of the function, perhaps in the class or namespace declaration. (also the fact that UnityCoach sees no issues lends this theory credence). I HAVE found that parenthesis errors like this usually do NOT say the line number CAUSING the problem.
Answer by $$anonymous$$ · Apr 23, 2017 at 03:09 PM
The actual mistake is in the line above the "}", this line "rb2d.velocity = Vector3.zero;". Try this "rb2d.velocity = new Vector3.zero;" because it is telling you that it needs an identifier.
I also think that it would generate the same problem with line 34
With all due respect, rb2d.velocity = Vector2.zero;
is absolutely correct. You only need to use the new
keyword when you create a new object, like rb2d.velocity = new Vector2 (0, 0);
.