Search Unity

Don't know why isn't it working

Discussion in 'Scripting' started by Basol23, Jan 21, 2019.

  1. Basol23

    Basol23

    Joined:
    Jan 21, 2019
    Posts:
    1
    Hello to everyone! I'm pretty new on scripting on C# so I've a script that isn't working still doesn't know why, any ideas? Here is the script:


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


    public class Movimiento2D : MonoBehaviour {


    private Rigidbody2D rb2d;

    void Start()
    {

    rb2d = GetComponent<Rigidbody2D>();

    }

    void FixedUpdate()
    {

    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

    Vector2 movement = new Vector2(moveHorizontal, moveVertical);

    rb2d.AddForce(movement);

    }
    }
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Please check the first post of the forum and use the formatting tags to make your code actually readable.

    Then please be a little more specific about "isn't working." Are there any errors? Did you put in a Debug.Log() call to see if the code runs? Is there smoke or fire pouring out of your computer? Give us some clues.
     
  3. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    130
    Use Debug.Log Debug.Log(moveHorinzontal) etc to check what the input values are. They are most probably too smol