Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

NullReferenceException error

$
0
0
so i was watching toutorials and i had code for AI and i reloaded to find it broken using UnityEngine; public class enemy : MonoBehaviour { public float speed = 10f; private Transform target; private int waypointIndex = 0; void Start() { target = waypoint_movement.points[0]; } void Update() { //movement and spped checks Vector3 dir = target.position - transform.position; transform.Translate(dir.normalized * speed * Time.deltaTime , Space.World); if (Vector3.Distance(transform.position , target.position) <=0.2f) { GetNextWaypoint(); } } //gets next waypoint void GetNextWaypoint() { if(waypointIndex >= waypoint_movement.points.Length -1) { Destroy(gameObject); return; } waypointIndex++; target = waypoint_movement.points[waypointIndex]; } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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