-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;
}
}
}
}