G
G
grogriy2022-03-31 21:05:24
C++ / C#
grogriy, 2022-03-31 21:05:24

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

1 answer(s)
G
GavriKos, 2022-03-31
@GavriKos

Are you able to read? How to add a number to a vector?
Learn seasharp first, and only then climb into the unit ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question