I followed an online tutorial which shows how to make a character both jump and move left and right:
The problem I'm experiencing now is this persistent error:CS1526: “A new expression requires () or after type” error
This is what my code looks like:
using UnityEngine;
using System.Collections;
public class KalusBeta : MonoBehaviour
{
private CharacterController controller;
private float verticalVelocity;
private float gravity = 14.0f;
private float jumpForce = 10.0f;
private void Start()
{
controller = GetComponent<CharacterController>();
}
private void Update()
{
if (controller.isGrounded)
{
verticalVelocity = -gravity * Time.deltaTime;
if (Input.GetKeyDown (KeyCode.Space))
{
verticalVelocity = jumpForce;
}
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
}
Vector3 moveVector = new Vector3.zero;
moveVector.x = Input.GetAxis("Horizontal") * 5.0f;
moveVector.y = verticalVelocity;
moveVector.z = Input.GetAxis("Vertical") * 5.0f;
controller.Move (moveVector * Time.deltaTime);
}
}
I’ve read through several people asking about the same error and tried multiple solutions. The line that’s causing issues is this one:
Vector3 moveVector = new Vector3.zero;
So I’ve tried the following:
Vector3 moveVector = new (Vector3.zero);
Vector3 moveVector = new (new string) {Vector3.zero};
But neither have worked. Does anyone see what I’m doing wrong here? I’m using C# and this is for a 3D game in Unity.