Example #1
0
 private void SpawnZombie()
 {
     if (currentGameStage.Equals(GameStage.NormalWave))
     {
         int row = Random.Range(0, 5);
         Debug.Log("Spawn Zombie in row" + row);
         float   xDelta = Random.Range(0.0f, 3.0f);
         Vector3 genPos = new Vector3(52.0f + xDelta, AxisManager.GetYAxis(row), AxisManager.GetZAxis(row));
         Instantiate(Resources.Load("ZombieNormal"), genPos, Quaternion.identity);
         normalWaveZombieNum--;
     }
     else if (currentGameStage.Equals(GameStage.FinalWave))
     {
     }
 }
Example #2
0
    void UpdatePlanting()
    {
        Vector3 mousePos = gameCam.ScreenToWorldPoint(Input.mousePosition);

        if (positionSelected && Input.GetMouseButtonDown(0) && planting == true && plantingType != PlantType.NotDefined)
        {
            if (sun >= ManagerDefine.GetSunNeedByPlantType(plantingType))
            {
                string prefabName = "";
                switch (plantingType)
                {
                case PlantType.Peashooter:
                    prefabName = "Peashooter";
                    break;

                case PlantType.Sunflower:
                    prefabName = "SunFlower";
                    break;

                case PlantType.SnowPeashooter:
                    prefabName = "SnowPeashooter";
                    break;

                case PlantType.WallNut:
                    prefabName = "WallNut";
                    break;

                default:
                    prefabName = "SunFlower";
                    break;
                }
                Instantiate(Resources.Load(prefabName), new Vector3(AxisManager.GetXAxis((int)currentMatrix.x),
                                                                    AxisManager.GetYAxis((int)currentMatrix.y), AxisManager.GetZAxis((int)currentMatrix.y)), Quaternion.identity);
                sun -= ManagerDefine.GetSunNeedByPlantType(plantingType);


                planting         = false;
                plantingType     = PlantType.NotDefined;
                positionSelected = false;
                CurrentPlantCard.CanBeSelected = false;

                Destroy(plantingSprite.gameObject);
            }
        }
        else if (Input.GetMouseButtonDown(1) && planting == true && plantingType != PlantType.NotDefined)
        {
            Destroy(plantingSprite.gameObject);
            planting         = false;
            plantingType     = PlantType.NotDefined;
            positionSelected = false;
        }
        else
        {
            if (planting == true && plantingType != PlantType.NotDefined)
            {
                // Moving the plant
                if (plantingSprite != null)
                {
                    SetCurrentMatrix(mousePos);
                    plantingSprite.transform.position = new Vector3(AxisManager.GetXAxis((int)currentMatrix.x),
                                                                    AxisManager.GetYAxis((int)currentMatrix.y) - 1.4f,
                                                                    AxisManager.GetZAxis((int)currentMatrix.y));
                }
                else
                {
                    plantingSprite = Instantiate(Resources.Load("PlantSprite", typeof(tk2dSprite)),
                                                 new Vector3(mousePos.x, mousePos.y, 6.0f),
                                                 Quaternion.identity) as tk2dSprite;
                    plantingSprite.SetSprite(ManagerDefine.GetSpriteNameByPlantType(plantingType));
                }
            }
        }
    }