I wrote the code but for some reason nothing works tell me what the problem is

Oleg

New member
Joined
Jul 1, 2022
Messages
3
Programming Experience
Beginner
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerScript: MonoBehaviour
{
    public float speed;
    private Rigidbody rb;
    float MoveHorizontal;
    float MoveVertical;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }


    void FixedUpdate()
    {
        Vector3 movement = new Vector3(MoveHorizontal, 0.0f, MoveVertical);

        rb.AddForce(movement * speed);
    }

    public void Up()
    {
        MoveVertical = 1f;
    }

    public void Down()
    {
        MoveVertical = -1f;
    }

    public void StopMoveVertical()
    {
        MoveVertical = 0f;
    }

    public void Left()
    {
        MoveVertical = 1f;
    }

    public void Right()
    {
        MoveHorizontal = -1f;
    }

    public void StopMoveHorizontal()
    {
        MoveHorizontal = 0f;
    }
}
 
That code does exactly what it does so clearly it is working perfectly. If you want code that does something else then you ought to write code that does that. If you were to actually explain what it is that you want the code to do and exactly how that code doesn't fit your needs, maybe we could help you.
 

Latest posts

Back
Top Bottom