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;
}
}
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);
}
}
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.