so if i play game enemy is going where it should go but not doing next thing i mean going to "path2"
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using UnityEngine;
public class EnemyPath : MonoBehaviour
{
public Transform path1;
public Transform path2;
bool onPath1;
bool toPath1;
bool toPath2;
bool onPath2;
private void Start()
{
toPath1 = true;
}
void Update()
{
if (onPath1 == true)
{
this.transform.position = path1.transform.position;
onPath2 = false;
toPath1 = false;
toPath2 = true;
onPath1 = false;
}
if (onPath2 == true)
{
this.transform.position = path2.transform.position;
onPath2 = false;
toPath1 = true;
toPath2 = false;
onPath1 = false;
}
if (toPath1 == true)
{
transform.position = Vector2.MoveTowards(transform.position, path1.transform.position, 3.5f * Time.deltaTime);
onPath2 = false;
toPath1 = true;
toPath2 = false;
onPath1 = false;
}
if (toPath2 == true)
{
transform.position = Vector2.MoveTowards(transform.position, path2.transform.position, 3.5f * Time.deltaTime);
onPath2 = false;
toPath1 = false;
toPath2 = true;
onPath1 = false;
}
}
}
↧