如何将 getter 和 setter 从一个类调用到另一个类?我必须从 Ball.cs 调用另一个名为 StartGame.cs 的类。我需要将它放在 StartGame.cs 中的计时器中。例如,在 Ball 类中。
public class Ball
{
public int speedX { get; private set; }
public int speedY { get; private set; }
public int positionX { get; private set; }
public int positionY { get; private set; }
public Ball(int speedX, int speedY, int positionX, int positionY)
{
this.speedX = speedX;
this.speedY = speedY;
this.positionX = positionX;
this.positionY = positionY;
}
public int setSpeedX(int newSpeedX)
{
speedX = newSpeedX;
return newSpeedX;
}
public int setSpeedY(int newSpeedY)
{
speedY = newSpeedY;
return newSpeedY;
}
public int setPositionX(int newPositionX)
{
positionX = newPositionX;
return newPositionX;
}
public int setPositionY(int newPositionY)
{
positionY = newPositionY;
return newPositionY;
}
}
谢谢你。