hello I have a problem please help
MissingComponentException: There is no 'Rigidbody' attached to the "player " game object, but a script is trying to access it.You probably need to ad
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;
}
}
Last edited by a moderator: