void Update() { if (FinishingGrid() && !inCollision) { transform.position = RandomDirVelo.Round2NearestPosFullTile(transform); curDir = RandomDirVelo.GetPossibleNewDir(transform); velocity = Direction.GetVector3ByDirection(curDir); } }
IEnumerator Detour(GameObject collisionGameObject) { inCollision = true; transform.position = RandomDirVelo.Round2NearestPosFullTile(transform); curDir = RandomDirVelo.GetPossibleNewDir(transform); velocity = Direction.GetVector3ByDirection(curDir); inCollision = false; yield return(null); }
IEnumerator Detour(GameObject collisionGameObject) { inCollision = true; transform.position = RandomDirVelo.Round2NearestPosFullTile(transform); curDir = RandomDirVelo.GetPossibleNewDir(transform); velocity = Direction.GetVector3ByDirection(curDir); for (float i = 0; i < 1; i += moveSpeed * Time.deltaTime) { yield return(new WaitForSeconds(Time.deltaTime)); } inCollision = false; }
IEnumerator move() { while (true) { if (!inCollision) { float moveTileNum = Mathf.Ceil(Random.Range(0, 3)); curDir = RandomDirVelo.GetPossibleNewDir(transform); velocity = Direction.GetVector3ByDirection(curDir); for (float i = 0; i < moveTileNum; i += Time.deltaTime * moveSpeed) { yield return(new WaitForFixedUpdate()); } velocity = Vector3.zero; transform.position = RandomDirVelo.Round2NearestPosFullTile(transform); yield return(new WaitForSeconds(waitingTime)); } } }
void Start() { transform.position = RandomDirVelo.Round2NearestPosFullTile(transform); originalPosition = transform.position; trapInStatic = true; }