// if not stunned then move the enemy when time is > _moveTime void Update() { if (!isStunned) { if (Time.time >= _moveTime) { EnemyMovement(); } else { _animator.SetBool("Moving", false); } } // Check to see if character is grounded by raycasting from the middle of the player // down to the groundCheck position and see if collected with gameobjects on the // whatIsGround layer _isGrounded = Physics2D.Linecast(_transform.position, groundCheck.position, whatIsGround); // if on ground, ensure waypoints move along ground if (_isGrounded) { if (myWaypoints == null || myWaypoints.Length == 0 && prefabMovingEnemy != null) { myWaypoints = new GameObject[2]; GameObject movingEnemy = Object.Instantiate(prefabMovingEnemy, transform.position, Quaternion.identity); int i = 0; foreach (Transform child in movingEnemy.transform) { if (child.CompareTag("Enemy")) { Destroy(child.gameObject); } else if (child.CompareTag("Waypoint")) { myWaypoints[i] = child.gameObject; i++; } } this.transform.SetParent(movingEnemy.transform); //GameObject wayPoint2 = Object.Instantiate(prefabWaypoint, transform.position, Quaternion.identity); //myWaypoints = new GameObject[] { wayPoint1, wayPoint2 }; } if (myWaypoints.Length > 1) { Vector3 groundLeft = new Vector3(ScreenUtils.GetCameraLeftEdge(Camera.main) + 1, -1.982f, 0f); Vector3 groundRight = new Vector3(ScreenUtils.GetCameraRightEdge(Camera.main) - 1, -1.982f, 0f); myWaypoints[0].transform.position = groundLeft; myWaypoints[1].transform.position = groundRight; } } }
protected override float GetNewLeftX(float currentX) { return(ScreenUtils.GetCameraLeftEdge(Camera.main)); }
protected override bool ExitScreenLeft() { return(transform.position.x < ScreenUtils.GetCameraLeftEdge(Camera.main)); }
protected virtual bool ExitScreenLeft() { float rightEdge = transform.position.x + halfWidth; return(rightEdge < ScreenUtils.GetCameraLeftEdge(this.currentCamera)); }
// Use this for initialization protected virtual void Start() { foreach (Camera c in Camera.allCameras) { if (c.CompareTag("BackgroundCamera")) { this.currentCamera = c; this.screenWidth = ScreenUtils.GetCameraRightEdge(this.currentCamera) - ScreenUtils.GetCameraLeftEdge(this.currentCamera); break; } } this.halfWidth = this.gameObject.GetComponent <BoxCollider2D>().size.x / 2; }