示例#1
0
    public Ball(Vector2 position, PhysicsMaterial2D physicsMaterial2D, BallGameColor ballGameColor)
    {
        _gameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        GameObject.DestroyImmediate(_gameObject.GetComponent <Rigidbody>());
        GameObject.DestroyImmediate(_gameObject.GetComponent <Collider>());

        _gameObject.AddComponent <CircleCollider2D>();
        _rigidBody = _gameObject.AddComponent <Rigidbody2D>();
        _rigidBody.sharedMaterial = physicsMaterial2D;


        _gameObject.transform.position = position;

        _rigidBody.velocity = new Vector2(0, 5);

        setBallColor(ballGameColor);
    }
示例#2
0
 public void setBallColor(BallGameColor ballGameColor)
 {
     if (ballGameColor == BallGameColor.Blue)
     {
         _gameObject.GetComponent <MeshRenderer>().material.color = Color.blue;
     }
     if (ballGameColor == BallGameColor.Green)
     {
         _gameObject.GetComponent <MeshRenderer>().material.color = Color.green;
     }
     if (ballGameColor == BallGameColor.White)
     {
         _gameObject.GetComponent <MeshRenderer>().material.color = Color.white;
     }
     if (ballGameColor == BallGameColor.Red)
     {
         _gameObject.GetComponent <MeshRenderer>().material.color = Color.red;
     }
 }