简体   繁体   English

统一5 C#对象平移和旋转

[英]unity 5 C# Object Translation and Rotation

In unity I am aware how to translate and rotate an object and I always do it in the Update function, the problem I am having is that I want a series of translations and rotations to happen in sequence but the only translation/rotation that occurs is the one that I call first in the code, is there any way to do a translation, wait a certain amount of time and then carry out another translation for example. 团结一致,我知道如何平移和旋转对象,并且我总是在Update函数中进行操作,我遇到的问题是我希望依次进行一系列平移和旋转,但是发生的唯一平移/旋转是我在代码中首先调用的那个代码,是否有任何方法可以进行翻译,请等待一段时间,然后再执行另一次翻译。 Thanks. 谢谢。

void Update () 
    {

        if (enemyHit == false)
        {
            //enemy moving
            transform.LookAt(TTarget);


        }
        else if (enemyHit == true)
        {
            Debug.Log (enemyHit);

            Evade();
        }
    }
IEnumerator Wait(float duration)
    {
        yield return new WaitForSeconds(duration);
    }

void Evade()
    {

        enemyHit = playerMovement.hitEnemy;

        transform.Translate(Vector3.back * Time.deltaTime * movementSpeed);
        Wait(2);
        transform.Rotate(0,90,0);

    }

I tried using a seperate function but that didnt seem to do anything. 我尝试使用单独的功能,但似乎没有任何作用。

IEnumerator Wait()
{
     yield return new WaitForSeconds(2);
}

You may want to start a CoRoutine as well. 您可能还需要启动CoRoutine。

StartCoroutine("Wait");

This should allow you to achieve what you're trying to do. 这应该可以让您实现您想要做的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM