-1
我想在unity5中無限上下移動對象(2D遊戲) 開始位置是當前位置,目標位置是當前位置+ y向量(0,y,0) ) 我希望能夠控制對象的速度。我怎樣才能將對象上下無限移動
我想在unity5中無限上下移動對象(2D遊戲) 開始位置是當前位置,目標位置是當前位置+ y向量(0,y,0) ) 我希望能夠控制對象的速度。我怎樣才能將對象上下無限移動
公共類moleMove:MonoBehaviour {
Vector3 current_position;
float direction = 1.0f;
float speed = 1.5f;
float heightlimit = 0.8f;
float timecount = 0.0f;
float timelimit = 2.5f;
void Start(){
current_position = this.transform.position;
}
void Update() {
transform.Translate (0, direction*speed*Time.deltaTime * 1, 0);
if (transform.position.y >current_position.y+heightlimit) {
direction = -1;
}
if (transform.position.y <current_position.y){
direction = 0;
timecount = timecount + Time.deltaTime;
if (timecount > timelimit) {
direction = 1;
timecount = 0;
}
}
}
}