Quantcast
Channel: Latest Questions by ARexx_808
Viewing all articles
Browse latest Browse all 4

How to move 2D enemy AI's along the x-Axis?

$
0
0
I have this spawning script for my 2D enemy AI's, but how can I implement a movement script along the x-Axis. I want the enemies to move left on the x-Axis. using UnityEngine; using System.Collections; using System.Collections.Generic; public class EnemySpawner:MonoBehaviour{ public float Speed ; public Transform spawnLeft; public Transform spawnRight; public List toSpawn = new List (); // Use this for initialization void Start () { InvokeRepeating ("spawnIt", 2, 4); } public void spawnIt() { Vector3 randomPos = Vector3.Lerp (spawnLeft.position, spawnRight.position, Random.Range (0,100) * 0.03f); int roll = Random.Range (0, toSpawn.Count); //Debeg.LogError("ROLL IS " + roll); GameObject prefab = toSpawn [roll]; GameObject.Instantiate (prefab, randomPos, Quaternion.identity); } // Update is called once per frame void Update () { transform.position = Vector3.MoveTowards(transform.position, spawnLeft.position, Speed); transform.position += transform.right * Speed * Time.deltaTime; } }

Viewing all articles
Browse latest Browse all 4

Trending Articles



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