Answer the question
In order to leave comments, you need to log in
Error CS0019 in unity 3d code, how to fix?
I just started learning unity with C#, I decided to make a simple puzzle game, I wrote the code to make the object move along the x, y axes. Gives an error message
Assets\Player.cs(15,4): error CS0019: Operator '+=' cannot be applied to operands of type 'Vector3' and 'int'. Help me fix it, I've already broken my head.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
//int KeyOne;
//int KeyTwo;
int moveDirection;
private void FixedUpdate()
{
//if(Input.GetKey(KeyOne))
if(Input.GetKey(KeyCode.W))
{
GetComponent<Rigidbody>().velocity += moveDirection;
}
//if(Input.GetKey(KeyTwo))
if(Input.GetKey(KeyCode.S))
{
GetComponent<Rigidbody>().velocity -= moveDirection;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question