- Home /
Movement Script stops working
Hi, I'm trying to make a game and I have 2 players on the same screen. Each of them has its own movement script, but when I move Player 2 and then stop its movement both scripts stop working. These are the scripts:
Player 1:
using UnityEngine;
public class VehicleMovement : MonoBehaviour
{
public Rigidbody rb;
public float movementForce = 100f;
void Update()
{
if(Input.GetKey("s"))
{
rb.AddForce(movementForce * Time.deltaTime, 0, 0);
}
if(Input.GetKey("w"))
{
rb.AddForce(-movementForce * Time.deltaTime, 0, 0);
}
}
}
Player 2:
using UnityEngine;
public class VehicleMovement1 : MonoBehaviour
{
public Rigidbody rb;
public float movementForce = 100f;
void Update()
{
if(Input.GetKey("down"))
{
rb.AddForce(movementForce * Time.deltaTime, 0, 0);
}
if(Input.GetKey("up"))
{
rb.AddForce(-movementForce * Time.deltaTime, 0, 0);
}
}
}
I hope someone can help me and thanks in advance!
What do you mean by the script stops working? Are you getting an error in the console?
If it stops responding, it's probably stuck in a loop somewhere.
How do you know it's these scripts causing the problem? Are there no other scripts in the project?
Try attaching the visual studio debugger to unity and launch the game. It should highlight where the code is getting stuck.
Your answer
Follow this Question
Related Questions
[C#] Quaternion Rotations with Input.GetAxis problems. 1 Answer
(Problem) Turning postprocessing on and off 0 Answers
Visual Studio Code Intellisense 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers