- Home /
Why am I getting error CS1525 when I use the question mark symbol?
I am very new to unity and have been following some tutorials to learn and to try to make a simple game. I followed this tutorial video to make a simple pong game. Here's my code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Ball : MonoBehaviour {
public float speed = 5f;
// Start is called before the first frame update
void Start()
{
float sx = Random.Range(0, 2) == ? -1 : 1;
float sy = Random.Range(0, 2) == ? -1 : 1;
GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, speed * sy, 0f);
}
// Update is called once per frame
void Update()
{
}
The problem is that in the lines that say
float sx = Random.Range(0, 2) == ? -1 : 1; and
float sy = Random.Range(0, 2) == ? -1 : 1;
the question marks in them are both marked with red squiggles underneath them and say CS1525 invalid expression term "?" when I hover over them. Also, this is in Visual Studio for Mac. Does anyone know how to fix this? Thanks in advance!
Answer by Bradwall · Dec 23, 2020 at 09:51 PM
Oops. Sorry about this. I did more research and tried checking my code against the video again, and I just had a typo!
Your answer
Follow this Question
Related Questions
Go back to previous asset version 0 Answers
Too Many Errors For No Reason! 0 Answers
C# script editor won't open? What should I do 2 Answers
Why error unexpected symbol `_timeout` 2 Answers
Can't Add Script Behaviour... 1 Answer