Inheritance: MonoBehaviour
	float timer;                                // Timer for counting up to the next attack.
	
	
	void Awake ()
	{
		// Setting up the references.
		player = GameObject.FindGameObjectWithTag ("Player");
		playerHealth = player.GetComponent <PlayerHealth> ();
		enemyHealth = GetComponent<EnemyHealth>();
	}
Esempio n. 2
0
    void Update()
    {
        if (player != null)
        {
            timer += Time.deltaTime;

            if (timer >= timeBetweenAttacks && playerInRange && enemyHealth.currentHealth > 0)
            {
                Attack();
            }

            if (playerHealth.currentHealth <= 0)
            {
                anim.SetTrigger("PlayerDead");
            }
        }
        else {
            player = GameObject.FindGameObjectWithTag("Player");
            if (player != null)
            {
                playerHealth = player.GetComponent<PlayerHealth>();
                enemyHealth = GetComponent<EnemyHealth>();
                anim = GetComponent<Animator>();
            }
        }
    }
Esempio n. 3
0
 // Use this for initialization
 void Awake()
 {
     spawnenemy = GameObject.Find("boss3spawn");
     Boss3Move.lebosspeutbouger = false;
     player = GameObject.FindGameObjectWithTag("Player");
     boss = GameObject.Find("CaveWorm");
     baril_pos_1 = GameObject.Find("baril_pos_1");
     baril_pos_2 = GameObject.Find("baril_pos_2");
     baril_pos_3 = GameObject.Find("baril_pos_3");
     baril_pos_4 = GameObject.Find("baril_pos_4");
     laser1 = GameObject.Find("laser1");
     laser2 = GameObject.Find("laser2");
     laser3 = GameObject.Find("laser3");
     laser4 = GameObject.Find("laser4");
     baril_fin = GameObject.Find("baril_fin");
     baril_start = GameObject.Find("baril_start");
     baril_start_h = GameObject.Find("baril_start_h");
     baril_pos_1_h = GameObject.Find("baril_pos_1_h");
     baril_pos_2_h = GameObject.Find("baril_pos_2_h");
     baril_pos_3_h = GameObject.Find("baril_pos_3_h");
     scriptdupersonnage = GameObject.FindGameObjectWithTag("Player").GetComponent<ScriptPersonnage>();
     enemyhealthSliderObjectGameObject = GameObject.FindGameObjectWithTag("BossHealthSlider3");
     playerHealth = player.GetComponent<PlayerHealth>();
     enemyHealth = GetComponent<EnemyHealth>();
     enemyHealthSlider = enemyhealthSliderObjectGameObject.GetComponent<Slider>(); // --
     enemyHealthSlider.maxValue = enemyHealth.startingHealth; // --
 }
	void OnTriggerStay2D (Collider2D other) {
		float currHit = 0f;
		int currScore = 0;
		if (other.tag == "Lazer") {
			currHit = lazerDamage;
			currScore = lazerScore;
			try {
				eHealthScript = gameObject.GetComponentInChildren <EnemyHealth> ();
				UIControl.Instance.AddScore (currScore);
				if (eHealthScript.EnemyIsDead (currHit)) {
					if (gameObject.name == "core"){
						// boss died
						UIControl.Instance.AddScore (5000);
						// for now its game over
						SceneManager.LoadScene("WinGame");
					}
					Instantiate (explosion, transform.position, transform.rotation);
					Destroy (gameObject);
				}
			} catch {
				print ("could not get " + gameObject.ToString () + " Script!");
				print ("script: " + eHealthScript.ToString());
			}
		} else {
			return;
		}
	}
Esempio n. 5
0
    void attack()
    {
        timer = 0f;

        if (attackingList.Count <= 0)
            return;
        else
            currentTarget = attackingList [0].transform;

        for (int i = 0; i< attackingList.Count; i++) {

            if(currentTarget.GetComponent<EnemyHealth>().health > attackingList [i].transform.GetComponent<EnemyHealth>().health)
                currentTarget = attackingList [i].transform;

        }

        currentEnemyHealth = currentTarget.GetComponent<EnemyHealth> ();

        if(currentEnemyHealth.health<=attackingDamage)
        {
            attackingList.Remove (currentTarget);
            currentEnemyHealth.attack(attackingDamage);
        }

        else
            currentEnemyHealth.attack(attackingDamage);
    }
	// Use this for initialization
	void Start () {
		player = GameObject.Find ("Player");
		EnemyHealth = GetComponent<EnemyHealth>();
		currentHealth = EnemyHealth.currentHealth;
		PlayerHealth = player.GetComponent<PlayerHealth> ();

	}
Esempio n. 7
0
 void Awake()
 {
     // Setting up the references.
     players = GameObject.FindGameObjectsWithTag("Player");
     enemyHealth = GetComponent<EnemyHealth>();
     anim = GetComponent<Animator>();
 }
Esempio n. 8
0
 void Awake()
 {
     player = GameObject.Find("Player");
     playerHealth = player.GetComponent<PlayerHealth> ();
     health = GetComponent<EnemyHealth> ();
     anim = GetComponent<Animator> ();
 }
 //SET UP
 void Awake()
 {
     _player = GameObject.FindGameObjectWithTag ("Player");
     _playerHealth = _player.GetComponent <PlayerHealth> ();//script reference
     _enemyHealth = GetComponent<EnemyHealth>();//script reference
     _anim = GetComponent <Animator> ();
 }
Esempio n. 10
0
    PlayerHealth playerHealth; // Reference to the player's health.

    #endregion Fields

    #region Methods

    void Awake()
    {
        enemyHealth = GetComponent<EnemyHealth>();
        nav = GetComponent<NavMeshAgent>();
        animation = GetComponent<Animation>();
        lebosspeutbouger = true;
    }
Esempio n. 11
0
 void Awake()
 {
     // Set up the references.
     enemyHealth = GetComponent<EnemyHealth>();
     nav = GetComponent<NavMeshAgent>();
     i = 0;
 }
Esempio n. 12
0
 // Use this for initialization
 void Awake()
 {
     Player = GameObject.FindGameObjectWithTag("Player").transform;
     playerHealth = Player.GetComponent<PlayerHealth>();
     enemyHealth = GetComponent<EnemyHealth>();
     nav = GetComponent<NavMeshAgent>();
 }
Esempio n. 13
0
 void Awake()
 {
     player = GameObject.FindGameObjectWithTag ("Player");
     //playerHealth = player.getComponent<PlayerHealth>();
     enemyHealth = GetComponent<EnemyHealth>();
     a = GetComponent<Animator> ();
 }
 void Start()
 {
     if(PlayerPrefs.GetString("level") == "Level2")
     {
         health1 = GameObject.FindWithTag("enemy1").GetComponent<EnemyHealth>();
         enemy1 = GameObject.FindWithTag("enemy1");
     }
     if(PlayerPrefs.GetString("level") == "Level3")
     {
         health1 = GameObject.FindWithTag("enemy2").GetComponent<EnemyHealth>();
         enemy1 = GameObject.FindWithTag("enemy2");
     }
     if(PlayerPrefs.GetString("level") == "Level4")
     {
         health1 = GameObject.FindWithTag("enemy3").GetComponent<EnemyHealth>();
         enemy1 = GameObject.FindWithTag("enemy3");
     }
     if(PlayerPrefs.GetString("level") == "Level5")
     {
         health1 = GameObject.FindWithTag("enemy4").GetComponent<EnemyHealth>();
         health2 = GameObject.FindWithTag("enemy5").GetComponent<EnemyHealth>();
         health3 = GameObject.FindWithTag("enemy6").GetComponent<EnemyHealth>();
         enemy1 = GameObject.FindWithTag("enemy4");
         enemy2 = GameObject.FindWithTag("enemy5");
         enemy3 = GameObject.FindWithTag("enemy6");
     }
 }
Esempio n. 15
0
 void Awake()
 {
     player1 = GameObject.FindGameObjectWithTag("Player");
     player2 = GameObject.FindGameObjectWithTag("Enemy");
     punchBox = GameObject.FindGameObjectWithTag("Punch");
     enemyHealth = player2.GetComponent<EnemyHealth>();
 }
 void Awake()
 {
     player = GameObject.FindGameObjectWithTag ("Player").transform; //Finds the  tag "Player" by looking through all the tags in a scene
     playerHealth = player.GetComponent <PlayerHealth> (); //Reference player health
     enemyHealth = GetComponent <EnemyHealth> (); //Reference enemy health
     nav = GetComponent <NavMeshAgent> (); //Pulls a reference to the component we have in editor
 }
 void Awake()
 {
     player = GameObject.FindGameObjectWithTag ("Player").transform;  //finds the player in the scene
     playerHealth = player.GetComponent <PlayerHealth> ();
     enemyHealth = GetComponent <EnemyHealth> ();
     nav = GetComponent <NavMeshAgent> ();
 }
Esempio n. 18
0
 void Awake()
 {
     player = GameObject.FindGameObjectWithTag ("Character");
     playerHealth = player.GetComponent <PlayerHealth> ();
     enemyHealth = GetComponent<EnemyHealth>();
     anim = GetComponent <Animator> ();
 }
 void Awake()
 {
     player = GameObject.FindGameObjectWithTag ("Player"); //find the player in the scene, used during awake so it only has to be called once
     playerHealth = player.GetComponent <PlayerHealth> (); //stores a reference to the PlayerHealth script
     enemyHealth = GetComponent<EnemyHealth>();
     anim = GetComponent <Animator> ();
 }
Esempio n. 20
0
 void Awake()
 {
     minDistance = 2.0f;
     enemyHealth = GetComponent <EnemyHealth> ();
     _animation = GetComponent<Animation> ();
     player = GameObject.FindGameObjectWithTag ("Player").transform;
 }
Esempio n. 21
0
 void Awake()
 {
     player = GameObject.Find("TP_Character");
     playerHealth = player.GetComponent <TP_Health> ();
     enemyHealth = GetComponent<EnemyHealth>();
     anim = GetComponent <Animator>();
 }
Esempio n. 22
0
	void Awake ()
	{
		player = GameObject.Find("Police");												//Find the police GameObject
		playerHealth = player.GetComponent <PlayerHealth> (); 							//get the PlayerHealth Script 
		enemyHealth = GetComponent <EnemyHealth>();										//Get EnemyHealth Script
	
	}
Esempio n. 23
0
 void Awake()
 {
     // Set up the references.
     Crocoanim = GetComponent<Animator>();
     enemyHealth = GetComponent<EnemyHealth>();
     nav = GetComponent<NavMeshAgent>();
     i = 0;
 }
Esempio n. 24
0
 // Use this for initialization
 void Start()
 {
     player = GameObject.FindGameObjectWithTag ("Player");
     planner = this.GetComponent<GoalPlanner> ();
     health = this.GetComponent<EnemyHealth> ();
     availableActions = new HashSet<Action> ();
     GetActions ();
 }
Esempio n. 25
0
    void Awake()
    {
        playerHealth = GameObject.FindGameObjectWithTag ("Player").GetComponent<PlayerHealth> ();
        enemyHealth = GameObject.FindGameObjectWithTag ("Enemy").GetComponent<EnemyHealth> ();

        playerMoney = GameObject.FindGameObjectWithTag ("Player").GetComponent<PlayerMoney> ();
        enemyMoney = GameObject.FindGameObjectWithTag ("Enemy").GetComponent<EnemyMoney> ();
    }
Esempio n. 26
0
    PH.PlayerHealth playerHealth; // Reference to the player's health.

    #endregion Fields

    #region Methods

    void Awake()
    {
        // Set up the references.
        player = GameObject.FindGameObjectWithTag ("Player").transform;
        playerHealth = player.GetComponent <PH.PlayerHealth> ();
        enemyHealth = GetComponent <EnemyHealth> ();
        nav = GetComponent <NavMeshAgent> ();
    }
Esempio n. 27
0
 public void Attack()
 {
     if (targetEnemy != null) {
         SoundManager.Instance.DogAttack();
         enemyHealth = targetEnemy.GetComponent<EnemyHealth> ();
         enemyHealth.ReduceHealth (10f);
     }
 }
Esempio n. 28
0
    void Awake()
    {
        enemyHealth = GetComponent<EnemyHealth>();
        spriteRenderer = GetComponent<SpriteRenderer>();
        firingScript = GetComponent<BasicEnemyFire>();

        ActivateGuard();
    }
 void Awake()
 {
     _enemyHealth = GetComponent<EnemyHealth>();
     _spiritBar = GetComponent<SpiritBar>();
     //_arenaManager.GetComponent<ArenaManager>();
     _EnemyAttackAnimation.GetComponent<EnemyAttackAnimation>();
     _DefendAnimation.GetComponent<DefendAnimation>();
 }
Esempio n. 30
0
    void Awake ()
    {
		// Because enemies do not exist at the very start of the game, we cannot use a public var
		player = GameObject.FindWithTag ("Player").transform;
        playerHealth = player.GetComponent <PlayerHealth> ();
        enemyHealth = GetComponent <EnemyHealth> ();
        nav = GetComponent <NavMeshAgent> ();
    }
 void OnTriggerEnter(Collider other)
 {
     if (other.tag != "Player" && isNotEnemySphereCollider(other))
     {
         //Debug.Log("DEBUGG"+other);
         RaycastHit hit       = new RaycastHit();
         GameObject gunBarrel = GameObject.Find("GunBarrel");
         Ray        ray       = new Ray(gunBarrel.transform.position, transform.TransformDirection(Vector3.forward));
         if (Physics.Raycast(ray, out hit, 400f))
         {
             if (hit.collider.tag != "Bullet")
             {
                 Instantiate(hitPrefab, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));
             }
         }
         if (other.tag == "Enemy")
         {
             enemyHealth = other.gameObject.GetComponentInChildren <EnemyHealth>();
             enemyHealth.TakeDamage(10);
         }
         Destroy(gameObject);
     }
 }
Esempio n. 32
0
    void Explode()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider nearbyObject in colliders)
        {
            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(power, transform.position, radius, upForce, ForceMode.Impulse);
            }

            EnemyHealth enemyHealth = nearbyObject.GetComponent <EnemyHealth>();
            if (enemyHealth != null)
            {
                enemyHealth.currentHealth = enemyHealth.currentHealth - damage;
            }
        }

        Destroy(gameObject);
        SoundManager.PlaySound("Explode");
        Debug.Log("BOOM");
    }
Esempio n. 33
0
 public void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Enemy") //do not explode against the player please
     {
         float critChance = Random.Range(0f, 1f);
         Debug.Log(critChance);
         if (critChance <= ps.criticalChance)
         {
             criticalHit = true;
         }
         else
         {
             criticalHit = false;
         }
         Debug.Log("Calc = " + baseDamage + " / 100 * " + ps.strength);
         var calculatedDamage = baseDamage / 100f * ps.strength;
         Debug.Log(calculatedDamage);
         damage = Mathf.RoundToInt(calculatedDamage);
         Debug.Log("Sending " + damage);
         EnemyHealth enemy = other.GetComponent <EnemyHealth>();
         enemy.TakeDamage(damage, damageType, criticalHit, enemy.transform.position + new Vector3(0f, 0.4f, 0f));
     }
 }
Esempio n. 34
0
    public void SpawnEnemyHealthBar(Transform _viewPoint, EnemyHealth _enemy)
    {
        // spawn health bar
        GameObject healthBarContainer = Instantiate(healthBarPrefab);

        // set parent
        healthBarContainer.transform.SetParent(GameObject.Find("EnemyHealthBars").transform, false);

        // name nicely in hierarchy
        healthBarContainer.name = this.gameObject.name + " " + healthBarContainer.name;
        if (healthBarContainer.name.Contains("(Clone)"))
        {
            healthBarContainer.name = healthBarContainer.name.Replace("(Clone)", "");
        }

        EnemyUIHealthBar script = healthBarContainer.GetComponentInChildren <EnemyUIHealthBar>();

        // set owner co-ordinate
        script.enemyTarget = _enemy.transform;
        // set look point for UI visibility
        script.viewPoint = _viewPoint;
        //healthBarDisplay = healthBarContainer.transform.GetChild(0).GetComponent<Image>();
    }
Esempio n. 35
0
    void Shoot()
    {
        currentAmmo--;
        PlayerVariable.currentAmmo[PlayerVariable.selectedWeapon] = currentAmmo;

        Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(.5f, .5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
        {
            health = hit.collider.GetComponent <EnemyHealth>();

            if (health != null)
            {
                health.Damage(gunDamage);
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * hitForce);
            }
        }
    }
Esempio n. 36
0
        void OnTriggerExit2D(Collider2D col)
        {
            switch (col.tag)
            {
            case "Suelo":
                player.IsGrounded = false;
                player.FalseAnyAnimStateAtAir();
                break;

            case "Enemy":
                enemyHealth = col.GetComponent <EnemyHealth>();
                if (enemyHealth.freezed && enemyHealth != null)
                {
                    player.FalseAnyAnimStateAtAir();
                    player.IsGrounded = false;
                }
                break;

            case "Platform":
                player.transform.parent = null; player.IsGrounded = false;
                break;
            }
        }
Esempio n. 37
0
    void ProcessRayCast()
    {
        RaycastHit hit;

        ammoSlot.ReduceCurrentAmmo(ammoType);

        if (Physics.Raycast(FPCamera.transform.position, FPCamera.transform.forward, out hit, range))
        {
            CreateHitImpact(hit);
            // TODO: add some hit effect for visual players
            EnemyHealth target = hit.transform.GetComponent <EnemyHealth>();
            if (target == null)
            {
                return;
            }
            // call a method on EnemyHealth that decreases the enemy's health
            target.TakeDamage(damage);
        }
        else
        {
            return;
        }
    }
Esempio n. 38
0
    void Explosion()
    {
        Instantiate(rocketExplosion, transform.position, transform.rotation);
        Collider2D[] objects = Physics2D.OverlapCircleAll(transform.position, explosionRadius);

        foreach (Collider2D nearbyObjects in objects)
        {
            Rigidbody2D rb = nearbyObjects.GetComponent <Rigidbody2D>();

            EnemyHealth enemy = nearbyObjects.GetComponent <EnemyHealth>();

            if (rb != null)
            {
                ExplosionForce2D.AddExplosionForce(rb, explosionForce * 100, transform.position, explosionRadius);
                if (rb.gameObject.tag == "Player")
                {
                    float proximity = (transform.position - rb.transform.position).magnitude;
                    float effect    = 1 - proximity / explosionRadius;
                    rb.GetComponent <PlayerHealth>().TakeDamage(25 * Mathf.RoundToInt(effect));
                }
            }
        }
    }
Esempio n. 39
0
    // Attack
    private void Attack()
    {
        // distance between the target and the player
        float distance = Vector3.Distance(target.transform.position, transform.position);

        // check where enemy is wrt the player
        // dot product returns value between 1 and -1. 1 means enemy is in front of us, -1 he's to the back
        Vector3 dir       = (target.transform.position - transform.position).normalized;
        float   direction = Vector3.Dot(dir, transform.forward);

        Debug.Log(direction);


        if (distance < 2.5f)         // check if close enough for attack to hit
        {
            if (direction > 0)       // check whether enemy is in front of us
            {
                // ref to EnemyHealth script of target and do damage
                EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
                eh.AdjustCurrentHealth(-10);
            }
        }
    }
Esempio n. 40
0
 public void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Enemy" || other.tag == "Obstacle") //do not explode against the player please
     {
         fbc.exploding = true;
         fbc.StartCoroutine("Explode");
         frostball.orbCount -= 1;
         if (other.tag == "Enemy")
         {
             float critChance = Random.Range(0f, 1f);
             if (critChance <= ps.criticalChance)
             {
                 criticalHit = true;
             }
             else
             {
                 criticalHit = false;
             }
             EnemyHealth enemy = other.GetComponent <EnemyHealth>();
             enemy.TakeDamage(damage, damageType, criticalHit, gameObject.transform.position);
         }
     }
 }
Esempio n. 41
0
    public void Shoot()
    {
        audio.Play();
        CurrentBullets--;
        Bullets.text = CurrentBullets.ToString();

        RaycastHit Hit;

        if (Physics.Raycast(FpsCam.transform.position, FpsCam.transform.forward, out Hit))
        {
            Debug.Log(Hit.transform.name);

            EnemyHealth Health = Hit.transform.GetComponent <EnemyHealth>();

            if (Health != null)
            {
                Health.TakeDamage(Damage);
            }

            GameObject HitEffect = Instantiate(HitEffets, Hit.point, Quaternion.LookRotation(Hit.normal));
            Destroy(HitEffect, 1f);
        }
    }
Esempio n. 42
0
    IEnumerator Shoot()
    {
        canShoot = false;
        if (ammoSlot.GetAmmoAmount(ammoType) > 0)
        {
            muzzleFlashFx.Play();
            RaycastHit hit;
            if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit, range))
            {
                GameObject impact = Instantiate(hitFx, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(impact, 0.1f);
                EnemyHealth target = hit.transform.GetComponent <EnemyHealth>();
                if (target)
                {
                    target.TakeDamage(attackPower);
                }
            }
            ammoSlot.ReduceAmmoAmount(ammoType);
        }
        yield return(new WaitForSeconds(shotDelay));

        canShoot = true;
    }
Esempio n. 43
0
    IEnumerator Shoot()
    {
        currAmmo--;
        muzzleFlash.Play();
        RaycastHit hit;

        //Debug.Log("Shoot");
        animator.SetBool("Fire", true);
        yield return(new WaitForSeconds(shootInterval));

        animator.SetBool("Fire", false);
        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit))
        {
            //Debug.Log(hit.transform.name);

            EnemyHealth target = hit.transform.GetComponent <EnemyHealth>();
            if (target != null)
            {
                target.TakeDamage(damage);
                //Debug.Log(target.GetHealth());
            }
        }
    }
Esempio n. 44
0
 void Shoot()
 {
     spotLight.enabled = true;
     laserLine.enabled = true;
     isShooting        = true;
     laserLine.SetPosition(0, laserBeamOrigin.transform.position);
     shootRay.origin    = laserBeamOrigin.transform.position;
     shootRay.direction = transform.forward;
     if (Physics.Raycast(shootRay, out shootHit, 100f, shootableMask))
     {
         laserLine.SetPosition(1, shootHit.point);
         EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();
         if (enemyHealth != null)
         {
             enemyHealth.TakeDamage(damagePoints, shootHit.point);
         }
     }
     else
     {
         laserLine.SetPosition(1, laserBeamEnd.transform.position);
     }
     PlayLaserSound();
 }
Esempio n. 45
0
    void OnCollisionEnter(Collision other)
    {
        Debug.Log("Hit " + other.gameObject.name);
        EnemyHealth destroyableObject = other.transform.GetComponent <EnemyHealth>();

        if (destroyableObject != null)
        {
            // if object is hit, subtract bullet damage from the object's health
            destroyableObject.LoseHealth(damage);
        }

        PlayerController player = other.transform.GetComponent <PlayerController>();

        if (player != null)
        {
            player.LoseHealth(damage);
        }

        var effect = Instantiate(bulletDestructEffect, gameObject.transform.position, Quaternion.identity);

        Destroy(effect, 2.0f);
        Destroy(gameObject);
    }
 void OnCollisionEnter(Collision col)
 {
     if (col.gameObject.tag == "Player")
     {
         PlayerHealth playerHealth = col.gameObject.GetComponent <PlayerHealth>();
         playerHealth.TakeDamage(damagePerShot);
         Destroy(gameObject);
     }
     if (col.gameObject.tag == "Enemy")
     {
         EnemyHealth enemyHealth = col.gameObject.GetComponent <EnemyHealth>();
         enemyHealth.TakeDamage(damagePerShot);
         Destroy(gameObject);
     }
     if (col.gameObject.tag == "Wall")
     {
         Destroy(gameObject);
     }
     if (col.gameObject.tag == "Door")
     {
         Destroy(gameObject);
     }
 }
Esempio n. 47
0
 void Shoot()
 {
     timer = 0f;
     print("Player Shoot");
     shootRay.origin    = transform.position;
     shootRay.direction = transform.forward;
     if (Physics.Raycast(shootRay, out hitPoint, range, mask))
     {
         if (hitPoint.collider.tag == "Player")
         {
             CmdPlayerShot(hitPoint.collider.name);
         }
         else
         {
             EnemyHealth enemyHealth = hitPoint.collider.GetComponent <EnemyHealth>();
             if (enemyHealth != null)
             {
                 print("EnemyFound");
                 enemyHealth.TakeDamage(damagePerShot, hitPoint.point);
             }
         }
     }
 }
Esempio n. 48
0
    // find a new target from the scenes
    void findTarget()
    {
        GameObject[] objects = GameObject.FindGameObjectsWithTag("enemy");
        //Debug.Log("num enemies: " + objects.Length);
        float min_distance = 1000000.0F;
        int   index        = -1;

        for (int i = 0; i < objects.Length; i++)
        {
            float dist = Vector3.Distance(objects[i].transform.position, transform.position);
            if (dist < min_distance && dist < 250)
            {
                min_distance = dist;
                index        = i;
            }
        }
        if (index >= 0)
        {
            target = objects[index];
            Debug.Log("found target");
            target_script = target.GetComponent <EnemyHealth>();
        }
    }
Esempio n. 49
0
    void Shoot(Collider other)
    {
        if (!startedShooting)
        {
            startedShooting = true;
            shotTakeStart   = Time.time;
        }

        if (Time.time - shotTakeStart < SHOT_DURATION)
        {
            return;
        }

        shooting = true;
        // The player takes damage.
        transform.LookAt(other.gameObject.transform.position);
        enemyHealth = other.gameObject.GetComponent <EnemyHealth> ();
        enemyHealth.TakeDamage(damage);

        // Display the shot effects.
        ShotEffects(other);
        startedShooting = false;
    }
Esempio n. 50
0
    private void ProcessRaycast()
    {
        RaycastHit hit;

        if (Physics.Raycast(FPCamera.transform.position, FPCamera.transform.forward, out hit, range))
        {
            CreateHitImpact(hit);
            print($"I hit this thing: {hit.transform.name} for {damage} damage.");
            //TODO: Add some viuals
            EnemyHealth target = hit.transform.GetComponent <EnemyHealth>();
            if (target == null)
            {
                return;
            }

            // Call method on enemy health
            target.TakeDamage(damage);
        }
        else
        {
            return;
        }
    }
Esempio n. 51
0
 /**
  * Method that makes the shoot
  * */
 void Shoot()
 {
     // Init the timer to 0
     timer = 0f;
     // Play the shoot audio
     gunAudio.Play();
     // Enable the light
     gunLight.enabled = true;
     // Play the particles effect
     gunParticles.Stop();
     gunParticles.Play();
     // Enable the shoot line and set it's position at the end of the gun barrel
     gunLine.enabled = true;
     gunLine.SetPosition(0, transform.position);
     // Set the origin of the ray at the barrel's end, and project it forward
     shootRay.origin    = transform.position;
     shootRay.direction = transform.forward;
     // Check if the shoot hits something
     if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
     {
         // Obtain the enemy health of the object shot
         EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
         // If the object shot is an enemy
         if (enemyHealth != null)
         {
             // Make the enemy take damage
             enemyHealth.TakeDamage(damagePerShot, shootHit.point);
         }
         // Draw the shoot line from the gun to the object
         gunLine.SetPosition(1, shootHit.point);
     }
     else
     {
         // If the gun hits nothing, draw the shoot line from the gun to the range units forward
         gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
     }
 }
Esempio n. 52
0
    void Shoot()
    {
        mussleFlash.Play();
        gunFireSource.Play();

        currentAmmo--;

        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            if (hit.transform.tag == "Enemy")
            {
                EnemyHealth health = hit.transform.GetComponent <EnemyHealth>();
                if (health != null)
                {
                    health.TakeDamage(1);
                }
            }
            else
            {
                Target target = hit.transform.GetComponent <Target>();
                if (target != null)
                {
                    target.TakeDamage(damage);
                }
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }

            GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactGO, 2f);
        }
    }
Esempio n. 53
0
    //玩家射击函数
    void Shoot()
    {
        timer = 0f;              //每次开枪时重置计时器

        gunAudio.Play();         //播放开枪音效

        gunLight.enabled = true; //激活子弹光照效果

        //停止之前枪口火焰粒子效果并重新播放枪口火焰粒子效果
        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;                     //激活子弹射线
        gunLine.SetPosition(0, transform.position); //射线初始坐标为0,即枪口位置

        shootRay.origin    = transform.position;    //射线发射点为枪口位置
        shootRay.direction = transform.forward;     //射线方向为枪口朝向,即Z轴正方向

        //如果子弹击中物体,其中shootableMask保证击中的物体都在可击中层中
        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
            //如果击中物体是敌人,则enemyHealth为非空,如果不是敌人(如障碍物)则为空
            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damagePerShot, shootHit.point); //对敌人造成伤害,shootHit.point为击中点
            }
            gunLine.SetPosition(1, shootHit.point);                    //设置子弹射线的起始点和终止点
        }
        //如果没有击中物体
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); //设置子弹射线的起始点和终止点,终止点为射程最远处
        }

        Invoke("DisableEffects", 0.05f);
    }
Esempio n. 54
0
    void Shoot()
    {
        timer = 0f;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
            if (enemyHealth != null)
            {
                //probable Damage
                float probableDamage;
                float localDamage;

                probableDamage = Random.Range(0, 3);
                localDamage    = damagePerShot - probableDamage;
                enemyHealth.TakeDamage(localDamage, shootHit.point, damageType);
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
Esempio n. 55
0
    void Shoot()
    {
        timer = 0f;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damagePerShot, shootHit.point);
            }
            // PvP version
            // PlayerHealth playerHealth = shootHit.collider.GetComponent <PlayerHealth> ();
            // if(playerHealth != null)
            // {
            //  playerHealth.TakeDamage (10);
            // }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
Esempio n. 56
0
    void DetectCollision()
    {
        Collider[] hit = Physics.OverlapSphere(transform.position, radius, collisionLayer);
        if (hit.Length > 0)
        {
            print("We Hit The " + hit[0].gameObject.name);
            if (hit[0].gameObject.name == "Player")
            {
                PlayerHealth playerHealth = hit[0].gameObject.GetComponent <PlayerHealth>();
                playerHealth.health -= 2;
                if (playerHealth.health <= 0)
                {
                    SceneManager.LoadScene("Highscore");
                }
            }
            else if (hit[0].gameObject.tag == "Enemy")
            {
                Vector3 hitFX_Pos = hit[0].transform.position;
                hitFX_Pos.y += 2.8f;
                hitFX_Pos.x -= 0.5f;
                Instantiate(hit_FX, hitFX_Pos, Quaternion.identity);

                EnemyHealth enemyHealth = hit[0].gameObject.GetComponent <EnemyHealth>();
                enemyHealth.health -= 2;
                if (enemyHealth.health <= 0)
                {
                    Vector3 enemy_exp_Pos = hit[0].transform.position;
                    enemy_exp_Pos.y += 1.8f;
                    enemy_exp_Pos.x -= 0.5f;
                    Instantiate(enemy_exp, enemy_exp_Pos, Quaternion.identity);
                    Destroy(hit[0].gameObject);
                    enemyKilled = true;
                }
            }
            gameObject.SetActive(false);
        }
    }
Esempio n. 57
0
    void OnTriggerStay2D(Collider2D other)
    {
        //print (damage);
        if (coolDown < Time.time)
        {
            if (other.tag == "Player" && !ignorePlayer)
            {
                PlayerController playerController = other.gameObject.GetComponent <PlayerController> ();
                playerController.addDamage(damage);
                coolDown = Time.time + damageRate;
                pushBack(other);
                if (destroyOnContact)
                {
                    Destroy(this.gameObject);
                }
            }
            else if (other.tag == "Enemy" && !ignoreEnemy)
            {
                EnemyHealth enemyHealth = other.gameObject.GetComponent <EnemyHealth> ();
                enemyHealth.addDamage(damage);
                coolDown = Time.time + damageRate;
                pushBack(other);

                if (destroyOnContact)
                {
                    Destroy(this.gameObject);
                }
            }
            else if (other.gameObject.layer == LayerMask.NameToLayer("Touchable") && !ignoreTouchable)
            {
                if (destroyOnContact)
                {
                    Destroy(this.gameObject);
                }
            }
        }
    }
Esempio n. 58
0
 void OnTriggerStay(Collider other)
 {
     if (other.CompareTag("Enemy"))
     {
         EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>();
         if (enemyHealth)
         {
             enemyHealth.takeDamage(damage);
             if (explosion)
             {
                 GameObject newExplosion = Instantiate(explosion, transform.position, transform.rotation);
                 if (newExplosion.GetComponent <AudioSource>())
                 {
                     newExplosion.GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("SoundVolume");
                 }
             }
             Destroy(gameObject);
         }
     }
     else if (other.CompareTag("Shield"))
     {
         ShieldHealth shieldHealth = other.GetComponent <ShieldHealth>();
         if (shieldHealth)
         {
             shieldHealth.takeDamage(damage);
             if (explosion)
             {
                 GameObject newExplosion = Instantiate(explosion, transform.position, transform.rotation);
                 if (newExplosion.GetComponent <AudioSource>())
                 {
                     newExplosion.GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("SoundVolume");
                 }
             }
             Destroy(gameObject);
         }
     }
 }
    private void FireRailgun()
    {
        if (canFire)
        {
            if (myPlayerController.GetControllerBool())
            {
                myPlayerController.RotateUsingController();
            }
            else
            {
                myPlayerController.FaceMouse();
            }

            var bulletFired = Instantiate(projectileToFire, gunBarrel.transform.position, transform.rotation);
            canFire = false;
            StartCoroutine(DelayFiring());

            RaycastHit hit;

            if (Physics.Raycast(gunBarrel.position, gunBarrel.forward, out hit, weaponRange))
            {
                Debug.Log("hit something");
                bulletFired.DestroyAfterDistanceTraveled(hit.distance);

                EnemyHealth target = hit.transform.GetComponentInParent <EnemyHealth>();
                if (target == null)
                {
                    myGameState.ResetRailgunDamage();
                    return;
                }

                Debug.Log("hit enemy");
                target.TakeDamage(projectileToFire.GetDamage());
                myGameState.ResetRailgunDamage(); // Put here so that it doesn't go down before the damage is processed
            }
        }
    }
Esempio n. 60
0
    public void OnTriggerEnter(Collider other)
    {
        // Find all the enemys in an area around the grenade
        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, enemy);

        for (int i = 0; i < colliders.Length; i++)
        {
            Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();

            if (!targetRigidbody)
            {
                continue;
            }

            targetRigidbody.AddExplosionForce(explosionForce, transform.position, explosionRadius);

            EnemyHealth enemyHealth = targetRigidbody.GetComponent <EnemyHealth>();

            if (!enemyHealth)
            {
                continue;
            }

            Vector3 explosionTarget = targetRigidbody.position - transform.position;

            float damage = CalculateDamage(explosionTarget);

            enemyHealth.TakeDamage((int)damage, targetRigidbody.position);
        }

        explosion.transform.parent = null;
        explosion.Play();

        Destroy(explosion.gameObject, explosion.duration);

        Destroy(gameObject);
    }