コード例 #1
0
ファイル: GameManager.cs プロジェクト: Dwitee/mobile-cricket
    // Use this for initialization
    void Start()
    {
        GameState.state = GameState.States.IDLE;
        ballRigidbody   = _ball.GetComponent <Rigidbody>();
        _ballScript     = _ball.GetComponent <CricketBall> ();

        bowlingDirection.Normalize();
        bowlingDirection *= Random.Range(bowlingForce.Min, bowlingForce.Max);
        mGameTimer        = _GameTime;
        mObjectPool       = new List <GameObject> ();
    }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: Dwitee/mobile-cricket
    /// <summary>
    /// Launchs the ball.
    /// </summary>
    public void LaunchBall()
    {
        if (_ballOnPitch != null)
        {
            _ballScript = _ballOnPitch.GetComponent <CricketBall> ();
        }

        if (_ballScript != null && pIsGameRunning)
        {
            _ballScript._BallLaunched = true;

            _FlickObj._AllowInput = false;

            // inDirection becomes the X/Z force of the ball. We also then add an upwards force
            Vector3 flickDir = _FlickObj.pFlickVector;
            if (flickDir.y < 0.0f)                      // temporary, to be capped between angle limits
            {
                flickDir.y = -flickDir.y;
            }
            Vector3 kickDir = new Vector3(_FlickObj.pFlickVector.x, Mathf.Sin(_AngleOfHit * Mathf.Deg2Rad), _FlickObj.pFlickVector.y).normalized;
            // kick force needs to be moved into camera space
            kickDir = Camera.main.transform.TransformDirection(kickDir);

            _ballScript.Launch(kickDir, _FlickObj.pFlickForce);
            _ballScript.AddTorque(_ballScript.transform.right, _FlickObj.pFlickForce);

            int score = ScoreManager.GetInstance().CalculateScore(_AngleOfHit, _FlickObj.pFlickForce);
            ScoreManager.GetInstance().AddToScore(score);
            HUDManager.GetInstance().DisplayScoreOnScreen(score, "Score");
            //DisplayScoreOnScreen(4);
        }
        else
        {
            Debug.LogError(" Theres no ball on the pitch  wait for the ball");
        }
    }