- Home /
My game keeps restarting at random
Im almost done with my game, but I've discovered that when i play it on my phone it restarts at random periods for no reason.
Has this happens to any of your guys in the past and how did you solve it?
You can be pretty sure that you have a bug somewhere in your code causing this.
Answer by Nosmo · Jun 10, 2019 at 12:27 AM
I worked it out that 5 seconds (the restart time) after the bullet is destroyed the game restarts.
When my character is going at speed setting 5 and I fire, that's when it goes pear shaped.
But when the characters speed is set to 0 and i fire it doesn't restart. Also any speed setting after 3 and the game restarts when I shoot,
the player is destroyed instantly when i set the speed to over 40.
This is my movement script: does anyone have suggestions?
using UnityEngine; using UnityStandardAssets.CrossPlatformInput;
public class PlayerL2R : MonoBehaviour {
private CharacterController charController;
private Vector3 moveVector;
public float forwardSpeed = 5.0f;
public float horizontalSpeed = 5.0f;
private GameObject Player;
// Start is called before the first frame update
public void Start()
{
charController = GetComponent<CharacterController>();
}
// Update is called once per frame
public void Update() //addition
{
MovePlayer();
}
public void MovePlayer() //addtion
{
moveVector = Vector3.zero;
moveVector.x = CrossPlatformInputManager.GetAxis("Horizontal") * horizontalSpeed; //left-right
moveVector.z = forwardSpeed; //forward
charController.Move(moveVector * Time.deltaTime);
}
}
Sounds like you are restarting if the Player collides with the bullet.
You should check what the bullet is colliding with, you can use CompareTag
to test which object has been hit, also I advise making use of Physics Layers.