M
M
m1rvi2020-11-22 21:54:44
C++ / C#
m1rvi, 2020-11-22 21:54:44

Why doesn't Unity recognize KeyCode?

I recently started to try myself in unity and on the first day there was an error..

I have an object like this:

square

5fbab36de67df055616167.png


And this script:
script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    [SerializeField] KeyCode KeyOne;
    [SerializeField] KeyCode KeyTwo;
    [SerializeField] Vector3 MoveDirection;

    private void FixedUpdate() 
     {
   if(Input.GetKey(KeyOne)) 
      {
      GetComponent<RigidBody>().velocity += MoveDirection;
    }
   if(Input.GetKey(KeyTwo)) 
      {
      GetComponent<RigidBody>().velocity -= MoveDirection;
    }

   }
}



I should have got these two buttons in the inspector, as in the guide, but nothing happens ..

Why? :/

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question