I’m trying to make a super simple topdown shooter game. I’m making the enemies slowly move towards you as you try to fight them off. Right now, I’ve just take the position of the player, then if the enemies x pos is less/greater than the players, increase/decrease it until they are the same. Same goes for y and z. For some reason I’m getting an error saying it expected a } after the first { in the update function, even though its matched at the end, after all the ifs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyAI : MonoBehaviour
{
public Transform playerPos;
public float enemySpeed;
// Update is called once per frame
void Update()
{
public float playerXPos = playerPos.position.x;
public float playerYPos = playerPos.position.y;
public float playerZPos = playerPos.position.z;
if(playerXPos < transform.position.x){
transform.position.x = transform.position.x - enemySpeed;
}
if(playerYPos < transform.position.y){
transform.position.y = transform.position.y - enemySpeed;
}
if(playerZPos < transform.position.z){
transform.position.z = transform.position.z - enemySpeed;
}
}
}