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][1] 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().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!
[1]: https://www.youtube.com/watch?v=jKbZM3KLqVI
↧