Other
Unexpected symbol 'direction', expecting '('
Hello Someone suggested me a script I finally found out how to use the scipt :) but then I got an error... Heres the full error also I mistyped Controller.
Assets/Scripts/PlayerControlle.cs(12,12): error CS1525 Unexpected symbol 'direction', expecting '(' Also here the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControlle : MonoBehaviour {
private Vector3 direction = Vector3.left;
private void Update()
{
if /* touch */
direction = -direction;
}
}
Answer by Pengocat · Mar 20, 2017 at 05:25 PM
An if statement needs a condition within a set of parenthesis that it can evaluate to either true or false. If the condition is true it will execute the following line of code or all of the code enclosed in angle brackets.
This is an example from the Unity documentation that uses Touch Input in an if statement to move the current GameObject the script is attached to.
public float speed = 0.1f;
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
// Get movement of the finger since last frame
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
// Move object across XY plane
transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
}
}
Answer by AnyOtherProgrammer · Mar 20, 2017 at 05:30 PM
On this script, the problem is very obvious, at least in my opinion. The syntax used fon an "if" statement looks like this:
if(a)
{
b
}
and in this example its checking if a(eg:A==B) is true, and if it is, doing b(eg:direction=-direction;) Unity is simply complaining about the fact that you dont have the first paranthesis. Replace that comment with an actual bool that dos whatever you want, put it in a set of paranthesis, and you'll be fine.
Eh I don't really know how to use that :( where do I add the parenthesis and if statement on the script?
Follow this Question
Related Questions
Help with script!!! 2 Answers
Cant Get a Bullet to Shoot (C#) 2 Answers
Split string into three pieces? 1 Answer
Vector3 not an identifier? 1 Answer