private void _ChangeOppositeDirection() { DeterminateSingleDirections direction = transform.parent.GetChild(0).transform.GetChild(0).GetComponent <DeterminateSingleDirections>(); direction.DirectionX = direction.DirectionX * -1; direction.DirectionY = direction.DirectionY * -1; }
private void _ChangeDirection(Vector3 contact) { DeterminateSingleDirections direction = transform.parent.GetChild(0).transform.GetChild(0).GetComponent <DeterminateSingleDirections>(); float xDirection = ((contact.x <0.1f && contact.x> -0.1f) ? Random.Range(0, 2) : direction.DirectionX * -1); float yDirection = ((contact.y <0.1f && contact.y> -0.1f) ? Random.Range(0, 2) : direction.DirectionY * -1); if (xDirection == 0) { direction.DirectionX = -0.5f; } else if (xDirection == 1) { direction.DirectionX = 0.5f; } else { direction.DirectionX = xDirection; } if (yDirection == 0) { direction.DirectionY = -0.5f; } else if (yDirection == 1) { direction.DirectionY = 0.5f; } else { direction.DirectionY = yDirection; } }
private void _setLinearDirection(GameObject bullet) { DeterminateSingleDirections direction = bullet.transform.GetChild(0).transform.GetChild(0).GetComponent <DeterminateSingleDirections>(); Vector2 targetPosition = Target.transform.position; if ((targetPosition.x - _parent.transform.position.x) > 0) { if ((targetPosition.y - _parent.transform.position.y) > 0) { direction.DirectionX = 0; direction.DirectionY = 1; } else { direction.DirectionX = 1; direction.DirectionY = 0; } } else { if ((targetPosition.y - _parent.transform.position.y) > 0) { direction.DirectionX = -1; direction.DirectionY = 0; } else { direction.DirectionX = 0; direction.DirectionY = -1; } } direction.GetDirection(); }
private void _SetHuntDirection(GameObject bullet) { DeterminateSingleDirections direction = bullet.transform.GetChild(0).transform.GetChild(0).GetComponent <DeterminateSingleDirections>(); Vector2 targetPosition = Target.transform.position; direction.DirectionX = targetPosition.x - _parent.transform.position.x; direction.DirectionY = targetPosition.y - _parent.transform.position.y; }
/* ************************************************ */ /* Coroutines */ /* ************************************************ */ // Offset time to launch first ball private IEnumerator _FirstLaunchCo() { for (int i = 0; i < numberOfBalls; i++) { yield return(new WaitForSeconds(_launchDelay)); GameObject myBall = _InstantiateNewBall(); DeterminateSingleDirections myBallDirection = myBall.transform.GetChild(0).transform.GetChild(0).GetComponent <DeterminateSingleDirections>(); NpcGeneralAddForces myBallSpeed = myBall.transform.GetChild(0).transform.GetChild(1).GetComponent <NpcGeneralAddForces>(); myBall.transform.SetParent(transform); myBall.layer = _layer; myBall.transform.GetChild(0).gameObject.layer = _layer; myBall.transform.GetChild(1).gameObject.layer = _layer; myBall.GetComponent <SpriteRenderer>().sortingLayerName = _sortingLayer; _UpdatePrefabParams(myBallDirection, myBallSpeed); } }
// Set prefab direction movement private void _UpdatePrefabParams(DeterminateSingleDirections enemyDirection, NpcGeneralAddForces enemySpeed) { enemyDirection.DirectionX = _directionX; enemyDirection.DirectionY = _directionY; enemySpeed._Speed = _prefabSpeed; }