I have a problem with restarting the game. My demo educational game working properly but after the restart game not working good for example jump not work. The speed getting lower
play my game : SIMMER.io
player scprit:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
//using UnityEngine.InputSystem;
using TMPro;
public class PlayerController : MonoBehaviour
{
private Rigidbody playerRB;
private float moveX, moveY, moveZ, yatay, dikey, yeksen;
private int count;
public TextMeshProUGUI score, zaman, can, durum;
public GameObject Powerobject, powerUpIndicator, winindicator, isongroundtest;
public bool GucAldi, isOnGround = true, gameover;
public ParticleSystem PlayerPowerUp;
private AudioSource playerAudio;
public AudioClip gemSound, JumpSound, YouWinSound, YouLoseSound, HurrySound, GetPowerUpSound, TeleportedSound;
[SerializeField] int cansayaci;
[SerializeField] private float zamansayaci = 10, tophizi = 5, AngularSpeed, GravityModifier = 10, JumpForce = 2000;
public Material GoldMetarial;
public Renderer Object;
public UnityEngine.UI.Button btn;
// public UnityEngine.UI.Text text;
//private InputActionAsset inputActions; new input için
//Keyboard keyboard;
private void Awake()
{
playerRB = GetComponent();
count = 0;
SetScoreText();
playerAudio = GetComponent();
Physics.gravity *= GravityModifier;
}
void Start()
{
}
private void Update()
{
winindicator.transform.position = transform.position + new Vector3(0, -0.5f, 0);
powerUpIndicator.transform.position = transform.position + new Vector3(0, 0.1f, 0);
if (!gameover)
{
zamansayaci -= Time.deltaTime;
zaman.text = “Time :” + " " + (int)zamansayaci + " "; // float int e ve sonra string e çevriliyor.
}
if (zamansayaci < 0 && !gameover)
{
gameover = true;
durum.text = “You lost”;
btn.gameObject.SetActive(true);
playerAudio.PlayOneShot(YouLoseSound, 0.5f);
Debug.Log(“Game over çaldı”);
}
if (transform.position.y < -45)
{
durum.text = “You lost”;
btn.gameObject.SetActive(true);
playerAudio.PlayOneShot(YouLoseSound, 0.060f);
gameover = true;
// Debug.Log(“Game over çaldı”);
}
}
void SetScoreText()
{
score.text = "Score : " + count.ToString();
if (count >= 15)
{
gameover = true;
winindicator.SetActive(true);
powerUpIndicator.SetActive(false);
durum.text = “You Win”;
btn.gameObject.SetActive(true);
playerAudio.PlayOneShot(YouWinSound, 0.5f);
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag(“Ground”))
{
isOnGround = true;
isongroundtest.SetActive(true);
}
}
private void OnTriggerEnter(Collider other) // collision = cls
{
if (other.gameObject.CompareTag(“pickup”))
{
playerAudio.PlayOneShot(gemSound, 0.5f);
zamansayaci += 3;
count++;
SetScoreText();
Debug.Log(count);
Destroy(other.gameObject);
}
else if (other.gameObject.CompareTag(“Powerobject”))
{
playerAudio.PlayOneShot(GetPowerUpSound, 0.5f);
powerUpIndicator.SetActive(true);
Destroy(other.gameObject);
Object.GetComponent().material = GoldMetarial;
// playerAudio.PlayOneShot(GetPowerUpSound, 1.0f);
GucAldi = true;
tophizi = 70;
}
else if (other.gameObject.CompareTag(“Teleport”))
{
playerAudio.PlayOneShot(TeleportedSound, 0.5f);
transform.position = new Vector3(0, 2.37f, -18);
Debug.Log(“teleported”);
}
}
void FixedUpdate()
{
//Vector3 movement = new Vector3(moveX, 0.0f, moveY); NEW İNPUT SYSTEM
if (!gameover)
{
yatay = Input.GetAxis(“Horizontal”);
dikey = Input.GetAxis(“Vertical”);
Vector3 kuvvet = new Vector3(yatay, 0, dikey);
playerRB.AddForce(kuvvet * tophizi, ForceMode.Impulse);
}
if (Input.GetKeyDown(KeyCode.Space) && isOnGround) // çok güzel bir bool örneği switch mantığı ile kod bloğunu aktif ya da pasif ediyor.
{
playerRB.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
playerAudio.PlayOneShot(JumpSound, 0.5f);
isOnGround = false;
isongroundtest.SetActive(false);
Debug.Log(“SPACE BASILDI”);
}
else if (gameover)
{
playerRB.velocity = Vector3.zero;
playerRB.angularVelocity = Vector3.zero;
}
}
}
Restart button scprit
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Buttons : MonoBehaviour
{
public void restrat()
{
SceneManager.LoadScene(“Level1”);
}
}