Ejemplo n.º 1
0
    void FixedUpdate()
    {
        if (zoneAnchor == null)
        {
            print("Creating a zone anchor in the zone's area");

            Quaternion rotation = new Quaternion();

            rotation.SetLookRotation(Vector3.up);

            zoneAnchor = pool.Spawn(zoneAnchorPrefab, generatedZone.Center, rotation);
        }
    }
Ejemplo n.º 2
0
    /**
     * Attempts to spawns a copy of spawnable from pool at the center of the SpawnAreaBehavior's collider rotated by initRot.
     *
     * @return the transform of the spawned object, null if unsuccessful
     */
    public Transform spawn(PathologicalGames.SpawnPool pool, Transform spawnable, Vector3 initRot)
    {
        Transform thingSpawned = pool.Spawn(spawnable);

        if (thingSpawned != null && !this.canSpawn(thingSpawned.GetComponent <Collider>()))
        {
            //failed to fit the object, despawn it!
            pool.Despawn(thingSpawned);

            thingSpawned = null;
        }
        else
        {
            Vector3 oldPos = thingSpawned.position;

            Vector3 oldRot = thingSpawned.eulerAngles;

            Vector3 newPos = this.GetComponent <Collider>().bounds.center;

            Vector3 newRot = initRot;

            if (thingSpawned.GetComponent <Rigidbody>())
            {
                //check the constraints and reset the new coords to old coords where contraints are set
                RigidbodyConstraints c = thingSpawned.GetComponent <Rigidbody>().constraints;

                newPos.x = (c & RigidbodyConstraints.FreezePositionX) == RigidbodyConstraints.FreezePositionX ? oldPos.x : newPos.x;
                newPos.y = (c & RigidbodyConstraints.FreezePositionY) == RigidbodyConstraints.FreezePositionY ? oldPos.y : newPos.y;
                newPos.z = (c & RigidbodyConstraints.FreezePositionZ) == RigidbodyConstraints.FreezePositionZ ? oldPos.z : newPos.z;

                newRot.x = (c & RigidbodyConstraints.FreezeRotationX) == RigidbodyConstraints.FreezeRotationX ? oldRot.x : newRot.x;
                newRot.y = (c & RigidbodyConstraints.FreezeRotationY) == RigidbodyConstraints.FreezeRotationY ? oldRot.y : newRot.y;
                newRot.z = (c & RigidbodyConstraints.FreezeRotationZ) == RigidbodyConstraints.FreezeRotationZ ? oldRot.z : newRot.z;
            }

            thingSpawned.position = newPos;

            thingSpawned.Rotate(newRot);
        }

        return(thingSpawned);       //if we've not yet returned, we've failed so return null
    }