コード例 #1
0
ファイル: Destroyable.cs プロジェクト: Booradley/ggj-2020
 private void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.CompareTag("Bounds"))
     {
         OnOutOfBounds?.Invoke(this);
         Destroy(gameObject);
     }
 }
コード例 #2
0
ファイル: ManualMove.cs プロジェクト: brnpham5/Pet-Game
        private void FixedUpdate()
        {
            if (autoMove == true && canMove == true)
            {
                movable.MoveRight();
            }

            if (gameObject.transform.position.x >= xBound)
            {
                OnOutOfBounds?.Invoke();
            }
        }
コード例 #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);
     }
 }
コード例 #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();
        }
    }
コード例 #5
0
 public void OutOfBounds()
 {
     OnOutOfBounds?.Invoke();
 }