Example #1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        //col.gameObject.SendMessage("ApplyDamage", bulletDamage, SendMessageOptions.DontRequireReceiver);
        //Debug.Log(col.gameObject.tag);

        if (isColliding)
        {
            return;
        }
        isColliding = true;

        if (col.gameObject.tag == "zombie")
        {
            ZombieScript zs = col.transform.root.GetComponent <ZombieScript>();

            if (zs != null)
            {
                int criticalMult = Random.Range(0f, 1f) < bulletCriticalChance ? bulletCriticalDamage : 1;

                if (col.gameObject.name == "weak spot")
                {
                    zs.ApplyDamage(bulletHeadDamage * criticalMult);
                }
                else
                {
                    zs.ApplyDamage(bulletDamage * criticalMult);
                }
            }

            Instantiate(bloodEffect, transform.position, Quaternion.Euler(rot));
        }

        Destroy(gameObject);
    }
Example #2
0
    /// <summary>
    /// Use this function for initialization that depends on other components being created.
    /// </summary>
    private void Start()
    {
        //we require a built up version of the character script.
        this.character = this.GetComponent <ZombieScript>();

        this.mainCamera = Camera.main;
    }
Example #3
0
	void OnTriggerEnter(Collider other) {
		if (other.gameObject.transform.tag == "Zombie") {

			// check parent's skill to see if zombie received headshot
			parentScript = sourceUnit.GetComponent<UnitScript>();
			zombieScript = other.gameObject.GetComponent<ZombieScript>();

			bool isMiss = false;
			
			// roll the dice
			float r = Random.Range(0f, 10f);
			if (r < parentScript.shootSkill) {
				// headshot
				zombieScript.Die();
			} else if (r - 1f < parentScript.shootSkill) {
				// bodyshot
				zombieScript.Slow();
			} else {
				// miss
				isMiss = true;
			}

			// destroy bullet last, parent becomes object pool
			if (!isMiss)
				this.Recycle();
		}
	}
    private void OnCollisionEnter(Collision col)
    {
        if (col.collider.CompareTag("Rock"))
        {
            GameObject.Instantiate(Replacement, transform.position, transform.rotation);
            Destroy(gameObject);

            foreach (var zombie in Zombies)
            {
                if (zombie == null)
                {
                    continue;
                }

                ZombieScript script = zombie.GetComponent <ZombieScript>();

                if (script == null)
                {
                    continue;
                }

                bool toChasePlayer = false;
                script.GetDamage(DamageToZombies, toChasePlayer);
            }
        }
    }
Example #5
0
 // Use this for initialization
 void Start()
 {
     Application.targetFrameRate = 60;
     winScore     = 0;
     playerHealth = 100;
     isShooting   = false;
     zomb         = (ZombieScript)zombie.GetComponent <ZombieScript>();
 }
 // Start is called before the first frame update
 void Start()
 {
     player       = GameObject.FindGameObjectWithTag("Player");
     playerHealth = player.GetComponent <PlayerControler>();
     zombieHealth = GetComponent <ZombieScript>();
     anim         = GetComponent <Animator>();
     rb           = GetComponent <Rigidbody2D>();
 }
Example #7
0
 void Awake()
 {
     this.character          = this.GetComponent <ZombieScript>();
     character.deathFunction = () =>
     {
         Application.LoadLevel(Application.loadedLevelName);
     };
 }
Example #8
0
    // Use this for initialization
    void Start()
    {
        Cam_main = Camera.main;
        player   = GameObject.FindWithTag("Player");
        fov      = player.GetComponent <FieldOfView>();
        canvas   = GetComponentInChildren <Canvas>().gameObject.transform;

        statistics   = player.GetComponent <stats>();
        zombiescript = GetComponent <ZombieScript>();
    }
Example #9
0
 void OnTriggerExit2D(Collider2D other)
 {
     if (other.tag == "Enemy")
     {
         ZombieScript z = other.GetComponent <ZombieScript>();
         if (neighbours.Contains(z))
         {
             neighbours.Remove(z);
         }
     }
 }
Example #10
0
    private void OnCollisionEnter(Collision collision)
    {
        ZombieScript targetScript = collision.transform.GetComponent <ZombieScript>();

        if (targetScript != null)
        {
            float dealingDamage = calculateDamage();
            bool  toChasePlayer = true;
            targetScript.GetDamage(dealingDamage, toChasePlayer);
        }
    }
Example #11
0
 private void AttractAllInRange()
 {
     Collider2D[] zombiesInRange = Physics2D.OverlapCircleAll(this.transform.position, currentRange, zombies);
     foreach (Collider2D Z in zombiesInRange)
     {
         ZombieScript zombieScript = Z.GetComponent <ZombieScript>();
         if (zombieScript.CurrentState != ZombieScript.ZombieState.Attracted)
         {
             zombieScript.AttractedToLocation(transform.position);
         }
     }
 }
Example #12
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Enemy" && other != GetComponent <Collider2D>())
     {
         ZombieScript z = other.GetComponent <ZombieScript>();
         if (!neighbours.Contains(z))
         {
             Debug.Log(gameObject.name + " Found " + other.name);
             neighbours.Add(z);
         }
     }
 }
Example #13
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.name != "Player")
     {
         ZombieScript zombie = collision.gameObject.GetComponent <ZombieScript>();
         if (zombie != null)
         {
             zombie.TakeDamage(bulletDamage);
         }
         Destroy(gameObject);
     }
 }
Example #14
0
 void Start()
 {
     health = 100;
     photonView = GetComponent<PhotonView> ();
     zombScript = GetComponent<ZombieScript> ();
     bool startAsZombie = true;
     foreach (ZombieScript zombz in FindObjectsOfType<ZombieScript>())
         if (zombz.isActiveAndEnabled)
             startAsZombie = false;
     if (startAsZombie)
         photonView.RPC ("TurnZomb", PhotonTargets.AllBufferedViaServer);
 }
Example #15
0
 public void ZombieDied(ZombieScript zombieScript)
 {
     if (zombiesAttachedToCrosshairA.Contains(zombieScript.gameObject))
     {
         zombiesAttachedToCrosshairA.Remove(zombieScript.gameObject);
         crosshairA.currentZombies--;
     }
     else if (zombiesAttachedToCrosshairB.Contains(zombieScript.gameObject))
     {
         zombiesAttachedToCrosshairB.Remove(zombieScript.gameObject);
         crosshairB.currentZombies--;
     }
 }
Example #16
0
            /// <summary>
            /// Se encarga de detectar la colision y con que colisiona
            /// </summary>
            /// <param name="other">
            /// Otro objeto con el cual colisiona
            /// </param>
            void OnCollisionEnter(Collision other)
            {
                if (other.gameObject.tag == "Heroe")
                {
                    SceneManager.LoadScene(0); // recarga la escena pero se podria crear una escena de derrota con un boton de reinicio
                }

                if (other.gameObject.tag == "Aldeano")
                {
                    ZombieScript zombie = other.gameObject.AddComponent <Enemy.ZombieScript>();
                    zombie.infected   = true;
                    zombie.zombieData = other.gameObject.GetComponent <Ally.AldeanoScript>().GetData();
                    Destroy(other.gameObject.GetComponent <Aldeno.AldeanoScript>());
                }
            }
Example #17
0
            /// <summary>
            /// Se encarga de detectar la colision y con que colisiona
            /// </summary>
            /// <param name="other">
            /// Otro objeto con el cual colisiona
            /// </param>
            void OnCollisionEnter(Collision other)
            {
                if (other.gameObject.tag == "Heroe")
                {
                    SceneManager.LoadScene(0);
                }

                if (other.gameObject.tag == "Aldeano")
                {
                    ZombieScript zombie = other.gameObject.AddComponent <Enemy.ZombieScript>();
                    zombie.infected   = true;
                    zombie.zombieData = other.gameObject.GetComponent <Ally.AldeanoScript>().GetData();
                    Destroy(other.gameObject.GetComponent <Aldeno.AldeanoScript>());
                }
            }
Example #18
0
    // Use this for initialization
    void Start()
    {
        controllerScript = this.GetComponent <Controller>();
        pathPercent      = controllerScript.PathToStop;
        mainStopPoints.Add(68);
        mainStopPoints.Add(98);
        mainStopPoints.Add(99);

        zombieScript0 = (ZombieScript)enemies[0].GetComponent(typeof(ZombieScript));
        zombieScript1 = (ZombieScript)enemies[1].GetComponent(typeof(ZombieScript));
        zombieScript2 = (ZombieScript)enemies[2].GetComponent(typeof(ZombieScript));
        zombieScript3 = (ZombieScript)enemies[3].GetComponent(typeof(ZombieScript));
        zombieScript4 = (ZombieScript)enemies[4].GetComponent(typeof(ZombieScript));
        zombieScript5 = (ZombieScript)enemies[5].GetComponent(typeof(ZombieScript));

        typerScript = (TyperHelper)GameObject.Find("MainCamera").GetComponent(typeof(TyperHelper));
    }
Example #19
0
    public void AssignZombieTargets()
    {
        if (humans.Count > 0)
        {
            for (int i = 0; i < zombies.Count; i++)
            {
                target = humans[0];
                Mathf.Abs(targetDistance = Vector3.Distance(zombies[i].transform.position, target.transform.position));
                tempDistance             = targetDistance;
                for (int j = 0; j < humans.Count; j++)
                {
                    tempDistance = Mathf.Abs(Vector3.Distance(zombies[i].transform.position, humans[j].transform.position));
                    if (tempDistance < targetDistance)
                    {
                        targetDistance = tempDistance;
                        target         = humans[j];
                    }
                }
                //sets the human target to the zombie
                zombies[i].target = target;

                //zombie is touching the human so turn human into the zombie
                if (targetDistance <= 1)
                {
                    humans.Remove((HumanScript)target);
                    zombieTemp = Instantiate(zombiePrefab);
                    zombieTemp.transform.position = target.transform.position;
                    zombies.Add(zombieTemp);
                    target.gameObject.SetActive(false);
                    target.humanFuturePositionPrefab.gameObject.SetActive(false);
                    target.zombieFuturePositionPrefab.gameObject.SetActive(false);
                    break;
                }
            }
        }
        else
        {
            //make the zombies stop moving when all humans are gone
            for (int i = 0; i < zombies.Count; i++)
            {
                zombies[i].target = null;
            }
        }
    }
Example #20
0
    void Start()
    {
        health     = 100;
        photonView = GetComponent <PhotonView> ();
        zombScript = GetComponent <ZombieScript> ();
        bool startAsZombie = true;

        foreach (ZombieScript zombz in FindObjectsOfType <ZombieScript>())
        {
            if (zombz.isActiveAndEnabled)
            {
                startAsZombie = false;
            }
        }
        if (startAsZombie)
        {
            photonView.RPC("TurnZomb", PhotonTargets.AllBufferedViaServer);
        }
    }
Example #21
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        bool damagePlayer = false;

        // Collision with enemy
        EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>();

        if (enemy != null)
        {
            // Kill the enemy

            /*
             * HealthScript enemyHealth = enemy.GetComponent<HealthScript>();
             * if (enemyHealth != null) enemyHealth.Damage(0);
             */
            ZombieScript zombie = collision.gameObject.GetComponent <ZombieScript>();
            if (zombie != null)
            {
                zombie.stopZombie();
            }
            damagePlayer = true;
        }

        Door door = collision.gameObject.GetComponent <Door>();

        if (door != null)
        {
            // Hit a door!
            GameManager.instance.LoadLevelWithCoords(door.nextX, door.nextY);
        }

        // Damage the player
        if (damagePlayer)
        {
            HealthScript playerHealth = this.GetComponent <HealthScript>();
            if (playerHealth != null)
            {
                playerHealth.Damage(1);
            }
        }
    }
Example #22
0
    // Start is called before the first frame update
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }

        zombies   = new List <ZombieScript>();
        humans    = new List <HumanScript>();
        obstacles = new List <Obstacle>();

        //creates obstacles at random positions
        for (int i = 0; i < numObstacles; i++)
        {
            obstacleTemp = Instantiate(obstaclePrefab);
            obstacleTemp.transform.position = new Vector3(Random.Range(-floorWidth, floorWidth), 3, Random.Range(-floorHeight, floorHeight));
            obstacles.Add(obstacleTemp);
        }

        //cerates humans at random positions
        for (int i = 0; i < numHumans; i++)
        {
            humanTemp = Instantiate(humanPrefab);
            humanTemp.transform.position = new Vector3(Random.Range(-floorWidth, floorWidth), 1, Random.Range(-floorHeight, floorHeight));
            humans.Add(humanTemp);
        }

        //creates zombies at random positions
        for (int i = 0; i < numZombies; i++)
        {
            zombieTemp = Instantiate(zombiePrefab);
            zombieTemp.transform.position = new Vector3(Random.Range(-floorWidth, floorWidth), 1, Random.Range(-floorHeight, floorHeight));
            zombies.Add(zombieTemp);
        }
    }
Example #23
0
    public void FindScript()
    {
        Component tempScript = currentObjects[globalIndex].GetComponent(typeof(MonoBehaviour));

        if (tempScript.GetType().Equals(typeof(TerroristScript)))
        {
            TerroristScript tempTerrorist = (TerroristScript)currentObjects[globalIndex].GetComponent(typeof(TerroristScript));
            tempTerrorist.KillToDeath();
        }
        if (tempScript.GetType().Equals(typeof(JungleCommandoScript)))
        {
            JungleCommandoScript tempJungle = (JungleCommandoScript)currentObjects[globalIndex].GetComponent(typeof(JungleCommandoScript));
            tempJungle.KillToDeath();
        }
        if (tempScript.GetType().Equals(typeof(ZombieScript)))
        {
            ZombieScript tempZombie = (ZombieScript)currentObjects[globalIndex].GetComponent(typeof(ZombieScript));
            tempZombie.KillToDeath();
        }
        if (tempScript.GetType().Equals(typeof(LightScript)))
        {
            LightScript tempLight = (LightScript)currentObjects[globalIndex].GetComponent(typeof(LightScript));
            tempLight.KillToDeath();
        }
        if (tempScript.GetType().Equals(typeof(ArmyScript)))
        {
            ArmyScript tempArmy = (ArmyScript)currentObjects[globalIndex].GetComponent(typeof(ArmyScript));
            tempArmy.KillToDeath();
        }
        if (tempScript.GetType().Equals(typeof(MissileScript)))
        {
            MissileScript tempMissile = (MissileScript)currentObjects[globalIndex].GetComponent(typeof(MissileScript));
            tempMissile.KillToDeath();
        }

        Killed(currentObjects[globalIndex]);
    }
Example #24
0
    void Shoot()
    {
        //Play sound
        sfxSource.clip = gunShotSound;
        sfxSource.Play();

        RaycastHit hit;

        if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit))
        {
            if (hit.transform.tag == "Zombie")
            {
                ZombieScript _zombieScript = hit.transform.GetComponent <ZombieScript>();
                Collider     col           = hit.collider.transform.GetComponent <Collider>();

                if (hit.collider.transform.tag == "Zombie")
                {
                    _zombieScript.health -= damage;
                    if (_zombieScript.health > 0)
                    {
                        GameObject _bloodSplatter0 = Instantiate(bloodSplatter, hit.transform.position + hit.transform.forward * .5f, Quaternion.identity) as GameObject;
                        GameObject _bloodSplatter  = Instantiate(bloodSplatter, hit.transform.position + hit.transform.forward * 4f, Quaternion.identity) as GameObject;
                    }
                    else if (_zombieScript.health <= 0)
                    {
                        GameObject _bloodSplatter0 = Instantiate(bloodSplatterDeath, hit.transform.position + hit.transform.forward * .5f, Quaternion.identity) as GameObject;
                        GameObject _bloodSplatter  = Instantiate(bloodSplatterDeath, hit.transform.position + hit.transform.forward * 4f, Quaternion.identity) as GameObject;
                    }
                }
                else if (hit.collider.transform.name == "Head")
                {
                    GameManager.score    += 1;
                    _zombieScript.health -= (damage * 5);
                    GameObject _bloodSplatter0 = Instantiate(bloodSplatterHead, new Vector3(hit.transform.position.x, hit.transform.position.y + 1f, hit.transform.position.z) + hit.transform.forward * .5f, Quaternion.identity) as GameObject;
                    GameObject _bloodSplatter  = Instantiate(bloodSplatterHead, new Vector3(hit.transform.position.x, hit.transform.position.y + 1f, hit.transform.position.z) + hit.transform.forward * 4f, Quaternion.identity) as GameObject;
                }
                else if (hit.collider.transform.name == "Helmet")
                {
                    GameObject helmetSparks0 = Instantiate(helmetSparks, new Vector3(hit.transform.position.x, hit.transform.position.y + 1.75f, hit.transform.position.z) + hit.transform.forward * .5f, Quaternion.identity) as GameObject;
                }
            }
            else if (hit.transform.tag == "Teleport")
            {
                ZombieTeleportScript _zombieScript = hit.transform.GetComponent <ZombieTeleportScript>();
                Collider             col           = hit.collider.transform.GetComponent <Collider>();

                if (hit.collider.transform.tag == "Teleport")
                {
                    _zombieScript.health -= damage;
                    if (_zombieScript.health > 0)
                    {
                        GameObject _bloodSplatter0 = Instantiate(bloodSplatter, hit.transform.position + hit.transform.forward * .5f, Quaternion.identity) as GameObject;
                        GameObject _bloodSplatter  = Instantiate(bloodSplatter, hit.transform.position + hit.transform.forward * 4f, Quaternion.identity) as GameObject;
                    }
                    else if (_zombieScript.health <= 0)
                    {
                        GameObject _bloodSplatter0 = Instantiate(bloodSplatterDeath, hit.transform.position + hit.transform.forward * .5f, Quaternion.identity) as GameObject;
                        GameObject _bloodSplatter  = Instantiate(bloodSplatterDeath, hit.transform.position + hit.transform.forward * 4f, Quaternion.identity) as GameObject;
                    }
                }
                else if (hit.collider.transform.name == "Head")
                {
                    GameManager.score    += 2;
                    _zombieScript.health -= (damage * 5);
                    GameObject _bloodSplatter0 = Instantiate(bloodSplatterHead, new Vector3(hit.transform.position.x, hit.transform.position.y + 1f, hit.transform.position.z) + hit.transform.forward * .5f, Quaternion.identity) as GameObject;
                    GameObject _bloodSplatter  = Instantiate(bloodSplatterHead, new Vector3(hit.transform.position.x, hit.transform.position.y + 1f, hit.transform.position.z) + hit.transform.forward * 4f, Quaternion.identity) as GameObject;
                }
            }
        }
    }
 private void Start()
 {
     _ZombieScript = gameObject.GetComponent<ZombieScript>();
 }
Example #26
0
	void Awake() {
		parentScript = transform.parent.GetComponent<ZombieScript>();
	}
Example #27
0
    // Update is called once per frame
    void Update()
    {
        temp = 50;

        for (int i = 0; i < humanScripts.Count; i++)
        {
            for (int j = 0; j < zombieScripts.Count; j++)
            {
                if (Vector3.Distance(humanScripts[i].transform.position, zombieScripts[j].transform.position) < temp)
                {
                    temp = Vector3.Distance(humanScripts[i].transform.position, zombieScripts[j].transform.position);
                    zombieScripts[j].seekTarget = humans[i];
                }

                if (Vector3.Distance(humanScripts[i].transform.position, zombieScripts[j].transform.position) < 5)
                {
                    newZ = true;
                    GameObject  tempHuman   = humans[i];
                    HumanScript tempScript  = humanScripts[i];
                    Vehicle     tempVehicle = humans[i].GetComponent <Vehicle>();
                    humans.Remove(tempHuman);
                    humanScripts.Remove(tempScript);

                    GameObject   newZombie  = Instantiate(zPrefab, tempHuman.transform.position, Quaternion.identity);
                    ZombieScript newZScript = newZombie.GetComponent <ZombieScript>();
                    newZScript.seekTarget = humans[i];
                    newZScript.maxSpeed   = 10;
                    newZScript.seekWeight = 1;
                    tempVehicle.maxSpeed  = 10;

                    zombie.Add(newZombie);
                    zombieScripts.Add(newZScript);

                    tempHuman.SetActive(false);

                    break;
                }

                Vehicle check = humanScripts[i].GetComponent <Vehicle>();

                if (Vector3.Distance(humanScripts[i].transform.position, zombieScripts[j].transform.position) < 15)
                {
                    check.mass = 0.25f;
                    steer      = check.Evade(zombieScripts[j].transform.position, zombieScripts[j].transform.position + this.transform.position);
                    steer.y    = 0;
                    check.ApplyForce(steer);
                }

                else
                {
                    Wander(check);
                }

                if (humanScripts[i].transform.position.x > 50 || humanScripts[i].transform.position.x < -50 || humanScripts[i].transform.position.z < -50 || humanScripts[i].transform.position.z > 50)
                {
                    steer   = check.Seek(new Vector3(0, 0.5f, 0));
                    steer.y = 0;
                    check.ApplyForce(steer);
                }
            }

            if (newZ)
            {
                newZ = false;
                break;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            Vehicle      tempVehicle = humans[0].GetComponent <Vehicle>();
            GameObject   newZombie   = Instantiate(zPrefab, Vector3.zero, Quaternion.identity);
            ZombieScript newZScript  = newZombie.GetComponent <ZombieScript>();
            newZScript.seekTarget = humans[0];
            newZScript.maxSpeed   = 10;
            newZScript.seekWeight = 1;
            tempVehicle.maxSpeed  = 10;

            zombie.Add(newZombie);
            zombieScripts.Add(newZScript);
        }


        if (humans.Count == 0)
        {
            for (int i = 0; i < zombieScripts.Count; i++)
            {
                Vehicle check = zombieScripts[i].GetComponent <Vehicle>();
                Wander(check);

                if (zombieScripts[i].transform.position.x > 50 || zombieScripts[i].transform.position.x < -50 || zombieScripts[i].transform.position.z < -50 || zombieScripts[i].transform.position.z > 50)
                {
                    steer   = check.Seek(new Vector3(0, 0.5f, 0));
                    steer.y = 0;
                    check.ApplyForce(steer);
                }
            }
        }

        foreach (Vehicle v in all)
        {
            for (int i = 0; i < blocks.Length; i++)
            {
                Vector3 avoidForce = v.AvoidObstacle(blocks[i], 4.5f);
                avoidForce.y = 0;
                v.ApplyForce(avoidForce);
            }
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            toggle = false;
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            toggle = true;
        }
    }
Example #28
0
 void Awake()
 {
     zombieScript = gameObject.GetComponentInParent<ZombieScript>();
 }
 // Use this for initialization
 void Start()
 {
     zombieScript = GetComponentInChildren <ZombieScript>();
     anim         = gameObject.GetComponentInChildren <Animator>();
     zombieScript.SetHitBox(gameObject.GetComponent <BoxCollider2D>());
 }