Exemplo n.º 1
0
 private void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.CompareTag("Bounds"))
     {
         OnOutOfBounds?.Invoke(this);
         Destroy(gameObject);
     }
 }
Exemplo n.º 2
0
        private void FixedUpdate()
        {
            if (autoMove == true && canMove == true)
            {
                movable.MoveRight();
            }

            if (gameObject.transform.position.x >= xBound)
            {
                OnOutOfBounds?.Invoke();
            }
        }
Exemplo n.º 3
0
 private void OnTriggerExit2D(Collider2D other)
 {
     if (other.tag == "Player" || other.tag == "Enemy")
     {
         if (OnOutOfBounds != null)
             OnOutOfBounds.Invoke(other.GetComponent<HealthComponent>());
     }
     else if (other.transform.parent.parent == null)
     {
         if (OnOutOfBoundsItem != null)
             OnOutOfBoundsItem.Invoke(other.transform);
     }
 }
Exemplo n.º 4
0
    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("bounds"))
        {
            Vector3 bounds   = other.GetComponent <Collider>().bounds.size;
            Vector3 otherPos = other.transform.position;

            bool wrapped = false;

            //If exit right
            if (transform.position.x >
                otherPos.x + (bounds.x / 2))
            {
                transform.position =
                    new Vector3(otherPos.x - (bounds.x / 2),
                                transform.position.y,
                                transform.position.z);
                wrapped = true;
            }
            else
            {
                //if exit left
                if (transform.position.x <
                    otherPos.x - (bounds.x / 2))
                {
                    transform.position =
                        new Vector3(otherPos.x + (bounds.x / 2),
                                    transform.position.y,
                                    transform.position.z);
                    wrapped = true;
                }
            }

            if (transform.position.z >
                otherPos.z + (bounds.z / 2))
            {
                //if exit forward
                transform.position =
                    new Vector3(
                        transform.position.x,
                        transform.position.y,
                        otherPos.z - (bounds.z / 2));
                wrapped = true;
            }
            else
            {
                //if exit backwards
                if (transform.position.z <
                    otherPos.z - (bounds.z / 2))
                {
                    transform.position =
                        new Vector3(
                            transform.position.x,
                            transform.position.y,
                            otherPos.z + (bounds.z / 2));
                    wrapped = true;
                }
            }

            //if exited bounds but none of the above
            //(they steer up and down to avoid bottom and top, but just in case)
            if (!wrapped)
            {
                Transform sP = BoidsManager.GetRandomSpawnPoint();

                //Respawn
                this.transform.position = sP.position;
                this.transform.rotation = sP.rotation;
#if DEBUG
                OobCount++;
                Debug.LogWarning(
                    "Out of bound count: " + OobCount +
                    " - total time: " + Time.time, gameObject);
#endif
            }


            //invoke out of bounds event if not null
            onOutOfBounds?.Invoke();
        }
    }
Exemplo n.º 5
0
 public void OutOfBounds()
 {
     OnOutOfBounds?.Invoke();
 }