第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

隨時間移動游戲?qū)ο?/h1>

隨時間移動游戲?qū)ο笪艺趶腟wift SpriteKit背景中學(xué)習(xí)UnityofSpriteKit,其中移動一個精靈的x位置就像運行一個動作一樣直接,如下所示:let moveLeft = SKAction.moveToX(self.frame.width/5, duration: 1.0)let delayAction = SKAction.waitForDuration(1.0)let handSequence = SKAction. sequence([delayAction, moveLeft])sprite.runAction(handSequence)我想知道一種等效或類似的方法,可以在特定的時間內(nèi)(例如,第二次)將sprite移動到一個特定的位置,并且在UPDATE函數(shù)中不需要調(diào)用這個延遲。
查看完整描述

3 回答

?
幕布斯7119047

TA貢獻1794條經(jīng)驗 獲得超8個贊

gjttt 1的答案是接近的,但缺少重要的功能和使用WaitForSeconds()用于移動游戲?qū)ο?/strong>是不能接受的。您應(yīng)該使用LerpCoroutineTime.deltaTime..你必須了解這些東西,才能從統(tǒng)一腳本中制作動畫。

public GameObject objectectA;public GameObject objectectB;void Start(){
    StartCoroutine(moveToX(objectectA.transform, objectectB.transform.position, 1.0f));}bool isMoving = false;
    IEnumerator moveToX(Transform fromPosition, Vector3 toPosition, float duration){
    //Make sure there is only one instance of this function running
    if (isMoving)
    {
        yield break; ///exit if this is still running
    }
    isMoving = true;

    float counter = 0;

    //Get the current position of the object to be moved
    Vector3 startPos = fromPosition.position;

    while (counter < duration)
    {
        counter += Time.deltaTime;
        fromPosition.position = Vector3.Lerp(startPos, toPosition, counter / duration);
        yield return null;
    }

    isMoving = false;}

類似的問題:SKAction.ScaleXto


查看完整回答
反對 回復(fù) 2019-07-02
?
慕萊塢森

TA貢獻1810條經(jīng)驗 獲得超4個贊

git 1的答案是好的,但是如果您不想使用禮貌,還有另一個解決方案。

你可以用InvokeRepeating反復(fù)觸發(fā)一個函數(shù)。

float duration; //duration of movementfloat durationTime; //this will be the value used to check if Time.
time passed the current duration setvoid Start(){
    StartMovement();}void StartMovement(){
    InvokeRepeating("MovementFunction", Time.deltaTime, Time.deltaTime); //Time.deltaTime is the time passed between two frames
    durationTime = Time.time + duration; //This is how long the invoke will repeat}void MovementFunction(){
    if(durationTime > Time.time)
    {
        //Movement
    } 
    else 
    {
        CancelInvoke("MovementFunction"); //Stop the invoking of this function
        return;
    }}


查看完整回答
反對 回復(fù) 2019-07-02
  • 3 回答
  • 0 關(guān)注
  • 448 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號