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

Enemy AI Error

$
0
0
Hey guys. I'm having a problem with my Enemy AI moving towards my player. It keeps saying "Object reference is not set to an instance of the Object". Think anyone can help me fix it? My code is this; public class AI1 : MonoBehaviour { private Vector3 Player; private Vector2 Playerdirection; private float Xdif; private float Ydif; private float speed; void start () { speed = 10; } void Update () { Player = GameObject.FindWithTag("Player").transform.position; Xdif = Player.x - transform.position.x; Ydif = Player.y - transform.position.y; Playerdirection = new Vector2 (Xdif, Ydif); GetComponent().AddForce(Playerdirection.normalized * speed); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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