Я работаю над игрой Flappy Bird и хотел, чтобы каналы работали быстрее по мере увеличения количества очков, поэтому я создал поле [Serialized] в своем LogicManager, но оно началось. Я попробовал скопировать код в новый скрипт, но он не исчез, я сделал совершенно новый префаб с нуля, ничего, я уже несколько дней просил AI.
Вот мой файл скрипта:
Код: Выделить всё
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
public class Pipe_slide : MonoBehaviour
{
public Logicscript Logicscript;
int currentScore;
int pastScore;
public float slideSpeed = 5;
private float dead_zone = -30;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
void Update()
{
currentScore = Logicscript.GetComponent().playerScore;
if (pastScore < currentScore)
{
slideSpeed += 0.1f;
pastScore = currentScore;
}
transform.position = transform.position + Vector3.left * slideSpeed * Time.deltaTime;
if (transform.position.x < dead_zone)
{
Destroy(gameObject);
}
}
}
Код: Выделить всё
using UnityEditor.Build.Content;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Logicscript : MonoBehaviour
{
public int playerScore = 0;
public Text scoreText;
public Text highScoreText;
public GameObject deathUI;
public GameObject pauseMenuUI;
[SerializeField] private AudioClip scoreIncreaseSound;
[SerializeField] private Slider MasterVolume;
[SerializeField] private Slider SoundFXVolume;
[SerializeField] private Slider MusicVolume;
[SerializeField] private AudioSource Music;
public void Start()
{
Time.timeScale = 1;
PlayerPrefs.GetFloat("MasterVolumePref");
PlayerPrefs.GetFloat("SoundFXVolumePref");
PlayerPrefs.GetFloat("MusicVolumePref");
MasterVolume.value = PlayerPrefs.GetFloat("MasterVolumePref");
SoundFXVolume.value = PlayerPrefs.GetFloat("SoundFXVolumePref");
MusicVolume.value = PlayerPrefs.GetFloat("MusicVolumePref");
}
void Update()
{
PlayerPrefs.SetFloat("MasterVolumePref", MasterVolume.value);
PlayerPrefs.SetFloat("SoundFXVolumePref", SoundFXVolume.value);
PlayerPrefs.SetFloat("MusicVolumePref", MusicVolume.value);
if (Input.GetKeyDown(KeyCode.Escape))
{
Scene activeScene = SceneManager.GetActiveScene();
if (Time.timeScale == 1 && deathUI.activeInHierarchy == false && activeScene.buildIndex == 1)
{
Time.timeScale = 0;
PauseMenu_UI();
}
else if (Time.timeScale == 0 && deathUI.activeInHierarchy == false && activeScene.buildIndex == 1)
{
Time.timeScale = 1;
UnPause();
}
else if (deathUI.activeInHierarchy == true)
{
// Do nothing if death UI is active
}
}
}
public void IncreaseScore()
{
playerScore += 1;
scoreText.text = playerScore.ToString();
}
public void UpdateHighScore()
{
if (PlayerPrefs.HasKey("SavedHighscore"))
{
if (playerScore > PlayerPrefs.GetInt("SavedHighscore"))
{
PlayerPrefs.SetInt("SavedHighscore", playerScore);
}
}
else
{
PlayerPrefs.SetInt("SavedHighscore", playerScore);
}
}
public void Death_UI()
{
deathUI.SetActive(true);
Music.Stop();
}
public void PauseMenu_UI()
{
pauseMenuUI.SetActive(true);
}
public void UnPause()
{
pauseMenuUI.SetActive(false);
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... e-mismatch
Мобильная версия