void Start() { enemy = GetComponent <Enemy2D>(); start_pos = transform.position; path_list.Add(transform.position); move_dir = Vector3.right * Mathf.Sign(transform.localScale.x); face_dir = move_dir; foreach (GameObject patrol in patrol_targets) { if (patrol) { path_list.Add(patrol.transform.position); } } current_path = 0; if (path_list.Count >= 2) { current_path = 1; //Dont start at start pos } if (path_list.Count <= 1) { path_rewind = Mathf.Sign(transform.localScale.x) < 0f; } }
public static Enemy2D GetNearest(Vector3 pos, float range = 999f) { float min_dist = range; Enemy2D nearest = null; foreach (Enemy2D point in enemy_list) { float dist = (point.transform.position - pos).magnitude; if (dist < min_dist) { min_dist = dist; nearest = point; } } return(nearest); }
void Start() { enemy_patrol = GetComponent <EnemyPatrol2D>(); enemy_follow = GetComponent <EnemyFollow2D>(); enemy = GetComponent <Enemy2D>(); enemy.onDeath += OnDeath; contact_filter = new ContactFilter2D(); contact_filter.layerMask = vision_mask; contact_filter.useLayerMask = true; contact_filter.useTriggers = false; if (vision_prefab) { GameObject vis = Instantiate(vision_prefab, GetEye(), Quaternion.identity); vis.transform.parent = transform; vision = vis.GetComponent <EnemyVision2D>(); vision.target = this; vision.vision_angle = vision_angle; vision.vision_range = vision_range; } ChangeState(EnemyLOS2DState.Patrol); }
void Start() { enemy = GetComponent <Enemy2D>(); }