【发布时间】:2016-06-23 11:48:57
【问题描述】:
我检查了如何在Update() 函数内移动带有动画的gameObject,以便您可以使用Time.deltaTime,但我试图将gameObject 移动到此函数之外,我还想移动@987654325 @ 不断(在屏幕上随机移动)。我当前没有动画的代码是:
using UnityEngine;
using System.Collections;
public class ObjectMovement : MonoBehaviour
{
float x1, x2;
void Start()
{
InvokeRepeating("move", 0f, 1f);
}
void move()
{
x1 = gameObject.transform.position.x;
gameObject.transform.position += new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), 0);
x2 = gameObject.transform.position.x;
if (x2 < x1)
gameObject.GetComponent<SpriteRenderer>().flipX = true;
else
gameObject.GetComponent<SpriteRenderer>().flipX = false;
}
void Update()
{
}
}
有什么更好的方法来实现这一点?
【问题讨论】:
标签: android unity3d unityscript