示例#1
0
    private void Start()
    {
        if (ball != null)
        {
            ball.OnScored += OnScored;
        }

        _inputs = new Dictionary <InputType, IRacketInput>
        {
            { InputType.Touch, touchInput }
        };

        playerRacket.SetInput(touchInput);

        _myBestScore    = PlayerPrefs.GetInt(myScoreKey, 0);
        _rivalBestScore = PlayerPrefs.GetInt(rivalScoreKey, 0);

        myScoreText.text    = string.Format(bestScoreFormat, _myScore.ToString(), _myBestScore.ToString());
        rivalScoreText.text = string.Format(bestScoreFormat, _rivalScore.ToString(), _rivalBestScore.ToString());

        _inputType = InputType.Touch;
        Restart(_inputType);
    }
示例#2
0
    private void Restart(InputType inputType)
    {
        _menuIsActive = false;
        menu.SetActive(_menuIsActive);
        Time.timeScale = 1;

        _myScore    = 0;
        _rivalScore = 0;

        myScoreText.text    = string.Format(bestScoreFormat, _myScore.ToString(), _myBestScore.ToString());
        rivalScoreText.text = string.Format(bestScoreFormat, _rivalScore.ToString(), _rivalBestScore.ToString());

        rivalRacket.SetInput(_inputs[inputType]);

        ball.transform.localPosition = new Vector2(10000, 10000);
        ball.SetSize(Random.Range(0.1f, 1f));
        ball.SetColor(Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f));

        if (_launchCoroutine != null)
        {
            StopCoroutine(_launchCoroutine);
        }
        _launchCoroutine = StartCoroutine(LaunchBall());
    }