- Home /
Unexpected symbol 'private' ...
Okay, noob question here. Running this simple script to move a cube that I've borrowed/adapted from someone else. Of course, I'm new to this whole thing and the script doesn't seem to like the use of "private" in this case, when calling MoveTowardsTarget. Result is, I don't know what to do... I feel like somewhere in there I probably need another "}" but where??
Any help would be appreciated, thanks!
void Update () {
private void MoveTowardsTarget() {
public float speed = 5;
Vector3 targetPosition = new Vector3(0,4,0);
Vector3 currentPosition = this.transform.position;
if(Vector3.Distance(currentPosition, targetPosition) > 0.1f) {
Vector3 directionOfTravel = targetPosition - currentPosition;
directionOfTravel.Normalize();
this.transform.Translate(
(directionOfTravel.x * speed * Time.deltaTime),
(directionOfTravel.y * speed * Time.deltaTime),
(directionOfTravel.z * speed * Time.deltaTime),
Space.World);
}
}
Answer by supernat · Mar 24, 2015 at 05:14 AM
Methods can not contain internal method definitions. Here you are trying to define the MoveTowardsTarget method inside the scope of the Update method. You can only call methods from within other methods, not define them. So maybe you want instead:
void Update() {
MoveTowardsTarget();
}
private void MoveTowardsTarget() {
... All the code to move towards the target
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
C# Parsing Error and Unexpected Symbol 1 Answer
Renderer on object disabled after level reload 1 Answer
c# parsin error 1 Answer