Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How can I make my enemy always look/flip towards my player (2D top-down)?

$
0
0
MY ENEMY SCRIPT: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy : MonoBehaviour { // Public Variables public float speed; public GameObject effect; // Private Variables private Transform playerPos; private Player player; private Shake shake; // Functions private void Start() { shake = GameObject.FindGameObjectWithTag("ScreenShake").GetComponent(); player = GameObject.FindGameObjectWithTag("Player").GetComponent(); playerPos = GameObject.FindGameObjectWithTag("Player").transform; } private void Update() { transform.position = Vector2.MoveTowards(transform.position, playerPos.position, speed * Time.deltaTime); } private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { shake.CamShake(); Instantiate(effect, transform.position, Quaternion.identity); player.health--; Destroy(gameObject); } if (other.CompareTag("Projectile")) { shake.CamShake(); Instantiate(effect, transform.position, Quaternion.identity); Destroy(gameObject); } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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