Quantcast
Viewing all articles
Browse latest Browse all 1488

Hi, im trying to make some simple 2d enemy path but somehow its not working as it should, btw im using Unity and learnig C# for 5 weeks so im sorry if its like a very simple question.

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; } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>