Keyword 'void' cannot be used in this context, cant figure out what to do
I am using visual studio, giving coding another shot and following a tutorial on a tower defense. Trying to code the enemy to go to the first waypoint then to the next.
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public float speed = 10f;
private Transform target;
private int wavepointIndex = 0;
//Target to the first point
void Start ()
{
target = Waypoints.points[0];
}
void Update()
{
// Get the next wavepoint
Vector3 dir = target.position - transform.position;
transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);
//Move torwards it unil it reaches the wavepoint (less than 0.2f < distance)
if (Vector3.Distance(transform.position, target.position) <= 0.2f)
{
GetNextWaypoint();
}
//the next wavepoint we are going to get is this one + 1
void GetNextWaypoint = ()
{
//set that wave point as the target
if (wavepointIndex >= Waypoints.points.Length - 1)
{
Destroy(gameObject);
}
wavepointIndex++;
target = Waypoints.points[wavepointIndex];
}
}
}
have 4 errors:
Keyword 'void' cannot be used i this context|Line 30
Invalid expression term ')'|Line 30
; expected| Line 30
Cannot use local variable 'GetNextWaypoint' before it is declared| Line 26
Answer by UnityCoach · Dec 24, 2016 at 02:00 PM
Your void GetNextWaypoint = () method body is within the Update body ;)
Your answer
Follow this Question
Related Questions
I need help I can't find the error in my code! 1 Answer
Unity 5 doesn't detect some positions in Vector3 0 Answers
Please Help "error CS1525: Unexpected symbol `void''' 1 Answer
How to convert an inputfield's string to an int? (C#) 1 Answer
[C#] The left-hand side of an assignment must be a variable, a property or an indexer 0 Answers