A teď k samotnému kódu:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bot7 : MonoBehaviour {
Transform tr;
bool isRotating;
public Vector3[] cesta;
public int indexC = 1;
public bool zpet;
void Start () {
tr = transform;
isRotating = true;
StartCoroutine (RotateBot ());
}
void Update()Pokud budete mít nějaké otázky, rád je zodpovím v komentářích.
{
if (indexC < cesta.Length && indexC > -1) {
tr.position = Vector3.MoveTowards (tr.position, cesta [indexC], 0.02f * Time.deltaTime);
if (zpet == false) {
if (Mathf.Approximately (tr.position.x, cesta [indexC].x) && Mathf.Approximately (tr.position.y, cesta [indexC].y)) {
indexC++;
}
} else {
if (Mathf.Approximately (tr.position.x, cesta [indexC].x) && Mathf.Approximately (tr.position.y, cesta [indexC].y)) {
indexC--;
}
}
} else {
if (zpet == false) {
zpet = true;
indexC = cesta.Length - 1;
} else {
zpet = false;
indexC = 0;
}
}
}
IEnumerator RotateBot()
{
while (isRotating) {
if (zpet == false) {
tr.Rotate (new Vector3 (0f, 0f, -120f * Time.deltaTime));
} else {
tr.Rotate (new Vector3 (0f, 0f, 120f * Time.deltaTime));
}
yield return null;
}
}
}
coder zeal
0 komentářů:
Okomentovat