void setObjectToWorld()
    {
        foreach (Transform child in wand) {
            spawnedObject = child.transform;
        }
        spawnedObject.parent = world;

        if (spawnedObject.tag == "footsoldiers") {
            spawnedObject.localScale = new Vector3(1.5f, 1.5f, 1.5f);
            spawnedObject.gameObject.AddComponent<Rigidbody>();
            spawnedObject.gameObject.AddComponent("SoldierMovement");
            spawnedObject.rigidbody.constraints = RigidbodyConstraints.FreezeRotationX;
            spawnedObject.position = new Vector3 (spawnedObject.position.x, world.position.y, spawnedObject.position.z);

            soldierMovementHandler = spawnedObject.gameObject.GetComponent("SoldierMovement") as SoldierMovement;
            soldierMovementHandler.notifyArchers();
        }

        if (spawnedObject.tag == "trebuchet") {
            spawnedObject.localScale = new Vector3(1.3f, 1.3f, 1.3f);
            spawnedObject.position = new Vector3 (spawnedObject.position.x, world.position.y + 0.7f, spawnedObject.position.z);
            spawnedObject.gameObject.AddComponent("CannonBehaviour");
            cannonBehaviour = spawnedObject.gameObject.GetComponent("CannonBehaviour") as CannonBehaviour;
            cannonBehaviour.notifyArchers();
        }
    }
Example #2
0
 void Awake()
 {
     anim           = GetComponent <Animator> ();
     playerAudio    = GetComponent <AudioSource> ();
     playerMovement = GetComponent <SoldierMovement> ();
     playerShooting = GetComponentInChildren <SoldierShooting> ();
     currentHealth  = startingHealth;
 }
Example #3
0
    public void spawnAllies()
    {
        soldierScript = soldierPrefab.GetComponentInChildren <SoldierMovement>();

        GameObject soldierOne = Instantiate(soldierPrefab, new Vector3(Random.Range(-100, 1500), 100, 0), Quaternion.identity) as GameObject;

        soldierOne.name             = "soldierOne";
        soldierOne.transform.parent = canvas.transform;

        GameObject soldierTwo = Instantiate(soldierPrefab, new Vector3(Random.Range(-100, 1500), 100, 0), Quaternion.identity) as GameObject;

        soldierTwo.name             = "soldierTwo";
        soldierTwo.transform.parent = canvas.transform;

        GameObject soldierThree = Instantiate(soldierPrefab, new Vector3(Random.Range(-100, 1500), 100, 0), Quaternion.identity) as GameObject;

        soldierThree.name             = "soldierThree";
        soldierThree.transform.parent = canvas.transform;

        soldierScript.isSoldierMoving = true;
    }
Example #4
0
    private void Update()
    {
        for (int i = 0; i < popUps.Length; i++)
        {
            if (i == popUpIndex)
            {
                popUps[i].SetActive(true);
            }
            else
            {
                popUps[i].SetActive(false);
            }
        }

        if (popUpIndex == 0)
        {
            if (inputScript.selectedMedic != null)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 1)
        {
            if (inputScript.movementScript.isMoving == true && inputScript.selectedMedic.GetComponent <RiskMeterController>().isSafe == false)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 2)
        {
            if (inputScript.selectedMedic.GetComponent <RiskMeterController>().isSafe == true)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 3)
        {
            if (Input.GetKeyUp(KeyCode.Return))
            {
                inputScript.spawnSoldiers = true;
                popUpIndex++;
                waitTime = 7f;
                canSpawn = true;
            }
        }
        else if (popUpIndex == 4)
        {
            soldierGameObject     = GameObject.FindGameObjectWithTag("Soldier");
            soldierMovementScript = soldierGameObject.GetComponent <SoldierMovement>();
            if (soldiersList.Count < 3)
            {
                soldiersList.AddRange(GameObject.FindGameObjectsWithTag("Soldier"));
            }

            foreach (GameObject sold in soldiersList)
            {
                if (sold.GetComponent <SoldierMovement>().isSoldierMoving == true)
                {
                    soldiersStopped = false;
                }
                else if (sold.GetComponent <SoldierMovement>().isSoldierMoving == false)
                {
                    soldiersStopped = true;
                }
            }
            if (soldiersStopped == true)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 5)
        {
            if (waitTime <= 0)
            {
                popUpIndex++;
            }
            else
            {
                waitTime -= Time.deltaTime;
            }
        }
        else if (popUpIndex == 6)
        {
            foreach (GameObject sold in soldiersList)
            {
                if (sold.GetComponent <SoldierMovement>().hasJoint == true)
                {
                    soldierPickedUp = true;
                }
            }

            if (soldierPickedUp == true)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 7)
        {
            if (soldierCountScript.soldiersSaved == 1)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 8)
        {
            if (Input.GetKeyUp(KeyCode.Return))
            {
                waitTime             = 30f;
                clockScript.dayCount = 2;
                popUpIndex++;
            }
        }
        else if (popUpIndex == 9)
        {
            medicButton.enabled = false;

            if (waitTime <= 0)
            {
                popUpIndex++;
            }
            else
            {
                waitTime -= Time.fixedDeltaTime;
            }
        }
        else if (popUpIndex == 10)
        {
            if (clockScript.upgradeSelected)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 11)
        {
            if (clockScript.upgradeOptionChosen)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 12)
        {
            riskMeterScript.currentRisk = 100;
            if (variablesScript.lives < 3)
            {
                wonScreen.SetActive(true);
                variablesScript.gameUI.SetActive(false);
                Time.timeScale = 1;
            }
        }
        if (soldiersList.Count == 0 && canSpawn)
        {
            inputScript.spawnSoldiers       = true;
            inputScript.haveSoldiersSpawned = false;
            soldiersList.AddRange(GameObject.FindGameObjectsWithTag("Soldier"));
        }
        soldiersList.RemoveAll(GameObject => GameObject == null);
    }
Example #5
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && upgradePanel.activeInHierarchy == false)
        {
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);


            if (hit)
            {
                if (hit.collider.tag == "Player")
                {
                    if (selectedMedic != null)
                    {
                        selectedMedic.GetComponentInChildren <ParticleSystem>().Stop();
                    }
                    selectedMedic = hit.collider.gameObject;
                    selectedMedic.GetComponentInChildren <ParticleSystem>().Play();
                }
                else
                {
                    selectedMedic = null;
                }
            }
        }

        if (Input.GetMouseButtonDown(1) && selectedMedic != null && selectedMedic.tag == "Player")
        {
            movementScript = selectedMedic.GetComponent <PlayerMovement>();
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

            if (hit)
            {
                movementScript.SetTargetPosition();
                movementScript.isMoving = true;
            }
            else
            {
                movementScript.SetTargetPosition();
                movementScript.isMoving = true;
            }
        }

        if ((spawnSoldiers == true && haveSoldiersSpawned == false))
        {
            soldierScript = soldierPrefab.GetComponentInChildren <SoldierMovement>();

            GameObject soldierOne = Instantiate(soldierPrefab, new Vector3(150, 150, 0), Quaternion.identity) as GameObject;
            soldierOne.name             = "soldierOne";
            soldierOne.transform.parent = canvas.transform;

            GameObject soldierTwo = Instantiate(soldierPrefab, new Vector3(200, 150, 0), Quaternion.identity) as GameObject;
            soldierTwo.name             = "soldierTwo";
            soldierTwo.transform.parent = canvas.transform;

            GameObject soldierThree = Instantiate(soldierPrefab, new Vector3(325, 150, 0), Quaternion.identity) as GameObject;
            soldierThree.name             = "soldierThree";
            soldierThree.transform.parent = canvas.transform;

            soldierScript.isSoldierMoving = true;
            haveSoldiersSpawned           = true;
        }
    }