コード例 #1
0
    public void ShootBall()
    {
        Rigidbody ballInstance = Instantiate(ballPrefab, spawner.position, spawner.rotation);

        b = ballInstance.GetComponent <Ball>();

        string       jsonText = Resources.Load <TextAsset>("Ball").ToString();
        BallVelocity ballData = BallVelocity.CreateFromJSON(jsonText);

        float colorRange = Random.Range(0.0f, 1.0f);

        if (colorRange < 0.33)
        {
            ballInstance.AddForce(spawner.up * ballData.red);
            ballInstance.GetComponent <Renderer>().material.color = Color.red;
        }
        else if (colorRange > 0.66)
        {
            ballInstance.AddForce(spawner.up * ballData.blue);
            ballInstance.GetComponent <Renderer>().material.color = Color.blue;
        }
        else
        {
            ballInstance.AddForce(spawner.up * ballData.green);
            ballInstance.GetComponent <Renderer>().material.color = Color.green;
        }
    }
コード例 #2
0
 public void InitBall()
 {
     ball = GameObject.FindGameObjectWithTag("Ball");
     Debug.Assert(ballVelocity is null, "You must add the ball in the scene");
     // renderer = testJoystick.GetComponent<Renderer>();
     ballVelocity = ball.GetComponent <BallVelocity>();
     Debug.Assert(ballVelocity, "You must add BallVelocity component to the ball");
 }
コード例 #3
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Ball"))
     {
         BallVelocity ballVelocity = other.gameObject.GetComponent <BallVelocity>();
         if (ballVelocity.IsDashing)
         {
             ballVelocity.Rebound(1f);
             Die();
         }
         else
         {
             KickTheFoockingBall();
             ballVelocity.Rebound(1.5f);
         }
     }
 }
コード例 #4
0
 private void Start()
 {
     renderer     = testJoystick.GetComponent <Renderer>();
     ballVelocity = ball.GetComponent <BallVelocity>();
     Debug.Assert(ballVelocity, "You must add BallVelocity component to the ball");
 }