added new enemy prefab, reconfigured enemy patrol script
enemy patrol now contains option for vertical movement
This commit is contained in:
@@ -4,11 +4,23 @@ using UnityEngine;
|
||||
|
||||
public class EnemyPatrol : MonoBehaviour {
|
||||
|
||||
public bool pinned = false;
|
||||
public float range;
|
||||
[HideInInspector] public bool pinned = false;
|
||||
|
||||
[Header("Horizontal")]
|
||||
public bool isHorizontal;
|
||||
public float rangeHorizontal;
|
||||
public float xLeft;
|
||||
public float xRight;
|
||||
public Vector2 movementVector = Vector2.right;
|
||||
public Vector2 movementVectorHorizontal = Vector2.right;
|
||||
|
||||
[Header("Vertical")]
|
||||
public bool isVertical;
|
||||
public float rangeVertical;
|
||||
public float yUp;
|
||||
public float yDown;
|
||||
public Vector2 movementVectorVertical = Vector2.up;
|
||||
|
||||
[Header("General")]
|
||||
public float moveSpeed;
|
||||
Animator animator;
|
||||
|
||||
@@ -18,19 +30,32 @@ public class EnemyPatrol : MonoBehaviour {
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
xLeft = transform.position.x - range;
|
||||
xRight = transform.position.x + range;
|
||||
movementVector *= moveSpeed;
|
||||
xLeft = transform.position.x - rangeHorizontal;
|
||||
xRight = transform.position.x + rangeHorizontal;
|
||||
|
||||
yDown = transform.position.y - rangeVertical;
|
||||
yUp = transform.position.y + rangeVertical;
|
||||
|
||||
movementVectorHorizontal *= moveSpeed;
|
||||
movementVectorVertical *= moveSpeed;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if (!pinned) {
|
||||
if (transform.position.x >= xRight || transform.position.x <= xLeft) {
|
||||
movementVector = -movementVector;
|
||||
GetComponent<SpriteRenderer>().flipX = !GetComponent<SpriteRenderer>().flipX;
|
||||
if (isHorizontal) {
|
||||
if (transform.position.x >= xRight || transform.position.x <= xLeft) {
|
||||
movementVectorHorizontal = -movementVectorHorizontal;
|
||||
GetComponent<SpriteRenderer>().flipX = !GetComponent<SpriteRenderer>().flipX;
|
||||
}
|
||||
transform.position += new Vector3(movementVectorHorizontal.x, 0, 0) * Time.deltaTime;
|
||||
}
|
||||
if (isVertical) {
|
||||
if (transform.position.y >= yUp || transform.position.y <= yDown) {
|
||||
movementVectorVertical = -movementVectorVertical;
|
||||
}
|
||||
transform.position += new Vector3(0, movementVectorVertical.y, 0) * Time.deltaTime;
|
||||
}
|
||||
transform.position += new Vector3(movementVector.x, 0, 0) * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +70,11 @@ public class EnemyPatrol : MonoBehaviour {
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawLine(new Vector3(transform.position.x - range, transform.position.y, transform.position.z), new Vector3(transform.position.x + range, transform.position.y, transform.position.z));
|
||||
if (isHorizontal){
|
||||
Gizmos.DrawLine(new Vector3(transform.position.x - rangeHorizontal, transform.position.y, transform.position.z), new Vector3(transform.position.x + rangeHorizontal, transform.position.y, transform.position.z));
|
||||
}
|
||||
if (isVertical) {
|
||||
Gizmos.DrawLine(new Vector3(transform.position.x, transform.position.y - rangeVertical, transform.position.z), new Vector3(transform.position.x, transform.position.y + rangeVertical, transform.position.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user