예제 #1
0
 /// <summary>
 /// Place leaves to the tree depending on its height
 /// </summary>
 /// <param name="height">height of the tree in blocks</param>
 /// <param name="pos">position ON TOP of the top log of wood of the tree</param>
 private void PlaceTreeLeaves(int height, Vector3 pos)
 {
     if (height == 6)
     {
         for (int y = (int)(pos.y); y > (int)(pos.y - 2); y--)
         {
             if (y == pos.y)
             {
                 TreeSpawn.CreateLeavesLayer1(blocks, new Vector3(pos.x, y, pos.z)).transform.SetParent(enviromentTransform);
                 //leavesBlock.transform.SetParent(transform);
             }
             else if (y == pos.y - 1)
             {
                 foreach (GameObject leaf in TreeSpawn.CreateLeavesLayer2(blocks, new Vector3(pos.x, y, pos.z)))
                 {
                     leaf.transform.SetParent(enviromentTransform);
                 }
             }
             else if (y == pos.y - 3)
             {
                 foreach (GameObject leaf in TreeSpawn.CreateLeavesLayer3(blocks, new Vector3(pos.x, y, pos.z)))
                 {
                     leaf.transform.SetParent(enviromentTransform);
                 }
             }
         }
     }
 }
예제 #2
0
 void Start()
 {
     spawnerObj  = GameObject.Find("Spawner");
     backGround  = GameObject.Find("BackGround1");
     resetScript = backGround.GetComponent <ScrollReset>();
     treeScript  = spawnerObj.GetComponent <TreeSpawn>();
     swipeScript = spawnerObj.GetComponent <Swiper>();
 }
예제 #3
0
 // Use this for initialization
 void Start()
 {
     newPlayer         = GameObject.FindGameObjectWithTag("Player");
     mySwiperScript    = newPlayer.GetComponent <Swiper>();
     spawner           = GameObject.Find("Spawner");
     myTreeSpawnScript = spawner.GetComponent <TreeSpawn>();
     treeHealth        = Random.Range(3, 6);
 }
예제 #4
0
    void KeyboardInput()
    {
        if (Input.GetKeyDown("1"))
        {
            SetSpell(Spell.Ice);
        }
        else if (Input.GetKeyDown("2"))
        {
            SetSpell(Spell.Fire);
        }
        else if (Input.GetKeyDown("3"))
        {
            SetSpell(Spell.Nature);
        }
        else if (Input.GetKeyDown("4"))
        {
            SetSpell(Spell.Lightning);
        }

        if (Input.GetMouseButtonDown(0))
        {
            CastSpell();
        }

        if (Input.GetMouseButton(0))
        {
            if (spell == Spell.Nature)
            {
                RaycastHit hit;
                Ray        ray = followCamera.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.transform.tag == "Floor")
                    {
                        currentTreeAim.transform.position = hit.point;
                    }
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (spell == Spell.Nature)
            {
                if (currentTreeSpawn != null)
                {
                    currentTreeSpawn.Despawn();
                }
                currentTreeSpawn = (TreeSpawn)Instantiate(treeSpawn, currentTreeAim.transform.position, Quaternion.identity);
                if (currentTreeAim != null)
                {
                    Destroy(currentTreeAim.gameObject);
                }
            }
        }
    }
예제 #5
0
    public TerrainChunk(Vector2 coord, HeightMapSettings heightMapSettings, MeshSettings meshSettings, LODInfo[] detailLevels, int colliderLODIndex, Transform parent, Transform viewer, Material material, GameObject treeMesh)
    {
        this.coord             = coord;
        this.detailLevels      = detailLevels;
        this.colliderLODIndex  = colliderLODIndex;
        this.heightMapSettings = heightMapSettings;
        this.meshSettings      = meshSettings;
        this.viewer            = viewer;

        sampleCenter = coord * meshSettings.meshWorldSize / meshSettings.meshScale;
        Vector2 position = coord * meshSettings.meshWorldSize;

        bounds = new Bounds(sampleCenter, Vector2.one * meshSettings.meshWorldSize);



        meshObject            = new GameObject("Terrain Chunk");
        meshRenderer          = meshObject.AddComponent <MeshRenderer>();
        meshFilter            = meshObject.AddComponent <MeshFilter>();
        meshCollider          = meshObject.AddComponent <MeshCollider>();
        meshRenderer.material = material;

        treeHolder = new GameObject("Tree Holder");
        treeHolder.transform.parent = meshObject.transform;

        meshObject.transform.position = new Vector3(position.x, 0, position.y);
        meshObject.transform.parent   = parent;
        SetVisible(false);

        treeSpawner        = treeHolder.AddComponent <TreeSpawn>();
        treeSpawner.prefab = treeMesh;

        lodMeshes = new LODMesh[detailLevels.Length];
        for (int i = 0; i < detailLevels.Length; i++)
        {
            lodMeshes[i] = new LODMesh(detailLevels[i].lod);
            lodMeshes[i].updateCallback += UpdateTerrainChunk;
            if (i == colliderLODIndex)
            {
                lodMeshes[i].updateCallback += UpdateCollisionMesh;
            }
        }

        maxViewDistance = detailLevels[detailLevels.Length - 1].visibleDistanceThreshold;
    }
    //Vector3 rotation;

    public void OnEnable()
    {
        treeSpawn = (TreeSpawn)target;
    }
 //Vector3 rotation;
 public void OnEnable()
 {
     treeSpawn = (TreeSpawn)target;
 }