using UnityEngine;
using System.Collections;
public class EnemyController : MonoBehaviour {
//In the editor select if you want the enemy to move vertical or horizontal. Also set the distance to move.
public bool moveVertical = false;
public bool moveHorizontal = true;
public float distanceToMove = 3.0f;
public GameObject other;
private Vector2 initPosition;
void Start()
{
initPosition = transform.position;
}
void Update()
{
//Moves enemy horizontally
if (moveHorizontal == true && moveVertical == false)
{
transform.position = new Vector3(Mathf.PingPong(Time.time, distanceToMove) + initPosition.x, transform.position.y, transform.position.z);
}
//Moves enemy vertically
if (moveHorizontal == false && moveVertical == true)
{
transform.position = new Vector3(transform.position.x, Mathf.PingPong(Time.time, distanceToMove) + initPosition.y, transform.position.z);
}
I got an error on this code in bold:
void OnTriggerEnter2D(Collider other) {
if (other.gameObject.tag == “Player”)
{
return;
}
Destroy(other.gameObject);
Destroy(gameObject);
}
}
}