没写好接下来的随机生成敌人 硬币的代码之前,不要在probability那里设置参数,不然会卡死
void Start()
{
LeftBorder = Camera.main.ViewportToWorldPoint(new Vector3(0, 0)).x;
RightBorder = Camera.main.ViewportToWorldPoint(new Vector3(1, 0)).x;
sp = GetComponent<SpriteRenderer>();
} player类要记得添加这一句
把移动方向设成-1,1
取startPos.x和当前位置.x差绝对值与distance比较,当大于舍得的距离时,方向取反
//-1 left 1 right -1 down 1 up
int direction = 1;
case 4://水平移动砖块
transform.Translate(new Vector2(speed * direction * Time.deltaTime, 0));
if (Mathf.Abs(startPos.x - transform.position.x) > distance) direction *= -1;
break;
case 5://垂直移动砖块
transform.Translate(new Vector2(0, speed * direction * Time.deltaTime));
if (Mathf.Abs(startPos.y - transform.position.y) > distance) direction *= -1;
break;