예제 #1
0
파일: RRGame.cs 프로젝트: galexcode/RRCube
    private void CalculatePlayerCube()
    {
        RaycastHit hit;

        Physics.Raycast(_player.transform.position, Vector3.down, out hit);

        RRCube activeCube = hit.collider.FindParentWithTag("Cube").GetComponent <RRCube>();

        // Activate doors
        activeCube.gameObject.SetActiveRecursively(true);

        // Assign to player
        _player.Cube = activeCube;

        // Destroy nonbound cubes
        List <RRCube> cubes = new List <RRCube>(_world.Values);

        foreach (RRCube cube in cubes)
        {
            if (cube != activeCube && cube.WorldBound == false)
            {
                _world.Remove(cube.WorldPosition);
                GameObject.Destroy(cube.gameObject);
            }
        }
    }
예제 #2
0
    public void SpawnCubeInDirection( Vector3 direction, RRCube relativeToCube )
    {
        Vector3 worldPosition = relativeToCube.WorldPosition +direction;

        // Did we generated this cube before?
        RRCube cube;
        if( !(cube = this.CubeAtWorldPosition( worldPosition )) ){
            // Create new Cube
            GameObject newCube;

            newCube = (GameObject)Resources.Load(_cubePrefabPath);
            newCube = (GameObject)GameObject.Instantiate(newCube, worldPosition *12, relativeToCube.transform.rotation);

            cube = newCube.GetComponent<RRCube>();
            cube.WorldPosition = worldPosition;

            // Add to generated cubes list
            _world.Add(worldPosition, cube);
        }

        if( direction.y < 0 ){
            cube.doorUp.gameObject.SetActiveRecursively(false);
        }else if( direction.y > 0 ){
            cube.doorDown.gameObject.SetActiveRecursively(false);
        }else if( direction.x < 0 ){
            cube.doorBack.gameObject.SetActiveRecursively(false);
        }else if( direction.x > 0 ){
            cube.doorFront.gameObject.SetActiveRecursively(false);
        }else if( direction.z < 0 ){
            cube.doorRight.gameObject.SetActiveRecursively(false);
        }else if( direction.z > 0 ){
            cube.doorLeft.gameObject.SetActiveRecursively(false);
        }
    }
예제 #3
0
파일: RRGame.cs 프로젝트: galexcode/RRCube
    public void SpawnCubeInDirection(Vector3 direction, RRCube relativeToCube)
    {
        Vector3 worldPosition = relativeToCube.WorldPosition + direction;

        // Did we generated this cube before?
        RRCube cube;

        if (!(cube = this.CubeAtWorldPosition(worldPosition)))
        {
            // Create new Cube
            GameObject newCube;

            newCube = (GameObject)Resources.Load(_cubePrefabPath);
            newCube = (GameObject)GameObject.Instantiate(newCube, worldPosition * 12, relativeToCube.transform.rotation);

            cube = newCube.GetComponent <RRCube>();
            cube.WorldPosition = worldPosition;

            // Add to generated cubes list
            _world.Add(worldPosition, cube);
        }

        if (direction.y < 0)
        {
            cube.doorUp.gameObject.SetActiveRecursively(false);
        }
        else if (direction.y > 0)
        {
            cube.doorDown.gameObject.SetActiveRecursively(false);
        }
        else if (direction.x < 0)
        {
            cube.doorBack.gameObject.SetActiveRecursively(false);
        }
        else if (direction.x > 0)
        {
            cube.doorFront.gameObject.SetActiveRecursively(false);
        }
        else if (direction.z < 0)
        {
            cube.doorRight.gameObject.SetActiveRecursively(false);
        }
        else if (direction.z > 0)
        {
            cube.doorLeft.gameObject.SetActiveRecursively(false);
        }
    }