Search Unity

Using Unity-Editor 2018.3.11f1 Linux Manjaro with logitech keyboard k380 moving player 2D

Discussion in 'Scripting' started by ijann_, Apr 9, 2019.

  1. ijann_

    ijann_

    Joined:
    Apr 8, 2019
    Posts:
    4
    Hi, I'm learning to program with unity,
    the problem I have is to give movement to a 2D player,
    I just want to operate it from the keyboard
    using the keyboard keys and the arrow keys of the keyboard,
    keyboard keys if I can move the player,
    using the arrows on the keyboard I can not, it fails,
    it moves once and then does not respond.
    Try many times to install monodevelop, but
    create an error when building the classes in the installation,
    I feel more comfortable with more modern IDE as Intellij RIDER,
    so I use that ide, what do you think the problem is?
    The attached script is from an Apress book "Developing 2D Games with Unity" 2018
    The IDE added the underscores for being private variables.

    The problem of keyboard dates he also has the same behavior on the keyboard of the laptop

    Any idea of the problem? please


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MovementController : MonoBehaviour
    6. {
    7.     public float movementSpeed = 3.0f;
    8.     private Vector2 _movement = new Vector2();
    9.     private Rigidbody2D _rgb2D;
    10.    
    11.     void Start()
    12.     {
    13.         _rgb2D = GetComponent<Rigidbody2D>();
    14.     }
    15.    
    16.     void FixedUpdate()
    17.     {
    18.         _movement.x = Input.GetAxis("Horizontal");
    19.         _movement.y = Input.GetAxis("Vertical");
    20.        
    21.         _movement.Normalize();
    22.         _rgb2D.velocity = _movement * movementSpeed;
    23.     }
    24. }
    25.