/* * The OnTriggerEnter function, void return type, parameter: Collider ***Please note that this is different then the others*** * If (tag of the Collider parameter equals the enemy tag) * -Create a variable with the type EnemyDamage and use the GetComponent in the Collider parameter to get a referece * to the EnemyDamage script. * -Create a switch statement in which you'll put the enemy type variable in the EnemyDamage script into the parenthesis * -A case for the first enemy type * -Call the Damage function from the EnemyDamage script and pass the weak damage variable into it * -A case for the second enemy type * -Call the Damage function from the EnemyDamage script and pass the strong damage variable into it * -A case for the third enemy type * -Call the Damage function from the EnemyDamage script and pass the super strong damage variable into it * -Destroy this bullet ***Make sure that this is included in the if statement*** */ void OnTriggerEnter(Collider collider) { if (collider.tag == "Enemy") { EnemyDamage enemydamage = collider.GetComponent <EnemyDamage>(); switch (enemydamage.enemytype) { case EnemyDamage.EnemyType.weak: enemydamage.Damage(weakDamage); break; case EnemyDamage.EnemyType.strong: enemydamage.Damage(strongDamage); break; case EnemyDamage.EnemyType.superstrong: enemydamage.Damage(superStrongDamage); break; default: break; } Destroy(gameObject); } }
private void ProccesRaycast() { RaycastHit hit; Vector2 withRecoilHit = UnityEngine.Random.insideUnitCircle * 2 * recoil; Vector3 fixedOrigin = new Vector3(FPCamera.transform.position.x + withRecoilHit.x, FPCamera.transform.position.y, FPCamera.transform.position.z + withRecoilHit.y); //Debug.Log(withRecoilHit.x + " " + withRecoilHit.y); if (Physics.Raycast(fixedOrigin, FPCamera.transform.forward, out hit, range)) { CreateHitImpact(hit); EnemyDamage target = hit.transform.GetComponent <EnemyDamage>(); if (target == null) { return; } target.ProcessDamageRecivedFromPlayer(); if (isExploding) { Instantiate(explosion, hit.transform.position, Quaternion.identity); } } else { return; } }
void ExecuteExplosion() { float multiplier = 1f; PlayPartSysExplosion(); float r = radius * multiplier; var cols = Physics.OverlapSphere(transform.position, r); var rigidbodies = new List <Rigidbody> (); foreach (var col in cols) { if (col.attachedRigidbody != null && !rigidbodies.Contains(col.attachedRigidbody)) { rigidbodies.Add(col.attachedRigidbody); } if (col.gameObject.tag.Equals("HitedEnemy")) { EnemyDamage enemDamage = col.gameObject.GetComponent <EnemyDamage> (); enemDamage.SetDamage(100); } } foreach (var rb in rigidbodies) { rb.AddExplosionForce(explosionForce * multiplier, transform.position, r, 1 * multiplier, ForceMode.Impulse); } }
IEnumerator Shoot() { canIFire = false; for (int i = 0; i < damage; i++) { if (SetTargetEnemy() != null) { EnemyDamage target = SetTargetEnemy(); muzzleFlash.Emit(1); Instantiate(projectileParticle, new Vector3(target.transform.position.x, target.transform.position.y + 3, target.transform.position.z), Quaternion.identity); if (i == damage - 1) { GetComponent <AudioSource>().PlayOneShot(lastGunShot, soundVolume * .6f); } else { GetComponent <AudioSource>().PlayOneShot(gunShot); } target.ProcessDamageRecivedFromMarines(); } yield return(new WaitForSeconds(.1f)); } yield return(new WaitForSeconds(3f / fireRate)); canIFire = true; }
// Triggers death for Animator Trigger public void TriggerDeath() { EnemyDamage children = gameObject.GetComponentInChildren <EnemyDamage>(); children.TurnOffAttack(); // Enemy can't retaliate when dead. gameObject.GetComponent <Animator>().SetTrigger("die"); }
void Start() { RB = GetComponent<Rigidbody> (); damagereference = GetComponent<EnemyDamage> (); if (damagereference.enemytype == EnemyDamage.num.drink) { direction = new Vector3 (0, Random.Range (0, 360), 0); transform.eulerAngles = direction; } else if (damagereference.enemytype == EnemyDamage.num.burger) { direction = new Vector3 (0, Random.Range (0, 360), 0); transform.eulerAngles = direction; } else if (damagereference.enemytype == EnemyDamage.num.fries) { direction = new Vector3 (0, Random.Range (0, 360), 0); transform.eulerAngles = direction; } }
void Update() { if (GameObject.FindWithTag("Enemy") != null) { if (GameObject.FindWithTag("Enemy").GetComponent <EnemyDamage>().isWet == true && GameObject.FindWithTag("Enemy").GetComponent <EnemyDamage>().takingElectricDamage == true) { if (!isCreated) { Instantiate(electricEffect, transform.position, transform.rotation); isCreated = true; GameObject.FindWithTag("Enemy").GetComponent <EnemyDamage>().takingElectricDamage = true; } damTimer -= Time.deltaTime; EnemyDamage enemyDamage = GameObject.FindWithTag("Enemy").GetComponent <EnemyDamage>(); enemyDamage.comboDamageAmount = enemyDamage.DOTDamageAmount * 2; if (damTimer <= 0) { enemyDamage.health -= enemyDamage.comboDamageAmount; damTimer = 1; Debug.Log(gameObject + " took " + enemyDamage.comboDamageAmount + " damage"); } } } }
void Start() { RB = GetComponent <Rigidbody> (); damagereference = GetComponent <EnemyDamage> (); if (damagereference.enemytype == EnemyDamage.num.drink) { direction = new Vector3(0, Random.Range(0, 360), 0); transform.eulerAngles = direction; } else if (damagereference.enemytype == EnemyDamage.num.burger) { direction = new Vector3(0, Random.Range(0, 360), 0); transform.eulerAngles = direction; } else if (damagereference.enemytype == EnemyDamage.num.fries) { direction = new Vector3(0, Random.Range(0, 360), 0); transform.eulerAngles = direction; } }
/* * The Update function, void return type, no parameters * Using the Rigidbody variable call AddForce and pass the forward direction times the speed as parameters */ void OnTriggerEnter(Collider hit) { if (hit.transform.tag == "enemy") { EnemyDamage ED = hit.transform.GetComponent <EnemyDamage>(); switch (ED.enemytype) { case EnemyDamage.num.burger: ED.damage(5); break; case EnemyDamage.num.fries: ED.damage(10); break; case EnemyDamage.num.drink: ED.damage(15); break; } Destroy(gameObject); } }
void Shoot() { audioSource.Play(); currentAmmo--; timeTillDestroy = Time.time + 0.02f; RaycastHit2D hitInfo = Physics2D.Raycast(weaponTip.position, weaponTip.up, range, ~LayerMask); var end = weaponTip.position + weaponTip.up.normalized * range; if (hitInfo.collider != null) { EnemyDamage enemy = hitInfo.transform.GetComponent <EnemyDamage>(); if (enemy != null) { enemy.TakeDamage(damage); } GameObject impactOB = Instantiate(impactFX, new Vector3(hitInfo.point.x, hitInfo.point.y, 0), Quaternion.LookRotation(hitInfo.normal)); impactOB.GetComponent <ParticleSystem>().Play(); Destroy(impactOB, 2f); lr.SetPosition(0, weaponTip.position); lr.SetPosition(1, hitInfo.point); } else { lr.SetPosition(0, weaponTip.position); lr.SetPosition(1, end); } timeTillNext = Time.time + 1f / fireRate; muzzleFlash.SetActive(true); }
// Update is called once per frame void Update() { Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; difference.Normalize(); float rotation_z = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotation_z); if (Input.GetKey(KeyCode.Mouse0) && currentEnergy > 0f) { RaycastHit2D hit = Physics2D.Raycast(firepoint.transform.position, transform.right * laserLength); if (hit.collider != null && hit.collider.gameObject.tag == "Enemy") { EnemyDamage enemyDamage = hit.collider.GetComponent <EnemyDamage>(); // Döp om till EnemyDamage if (enemyDamage != null) { enemyDamage.TakeDamage(); } } Debug.DrawRay(firepoint.transform.position, transform.right * laserLength, Color.red); } if (Input.GetKey(KeyCode.Mouse0)) { TakeEnergy(); } else { AddEnergy(); } }
void UpdateEnemy() { float shortestDistanceToEnemy = Mathf.Infinity; GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); //string reference GameObject nearestTarget = null; foreach (GameObject enemy in enemies) { float distanceToEnemy = Vector3.Distance(this.transform.position, enemy.transform.position); if (distanceToEnemy < shortestDistanceToEnemy) { shortestDistanceToEnemy = distanceToEnemy; nearestTarget = enemy; } } if (nearestTarget != null && shortestDistanceToEnemy <= range) { target = nearestTarget.transform; targetEnemyForDMG = nearestTarget.GetComponent <EnemyDamage>(); targetEnemy = nearestTarget.GetComponent <Enemy>(); } else { target = null; } }
void OnParticleCollision(GameObject other) { if (other.name == "Rock") { if (GameObject.Find("testCrystal") != null && GameObject.Find("Box001") != null) { GameObject go = GameObject.Find("testCrystal"); GameObject go2 = GameObject.Find("Box001"); unfreezeTarget.EffectTimer = 0; deactivateByTime.DeactivateTime = 0; startDelay.Delay = 0; Destroy(go); Destroy(go2); } if (GameObject.FindWithTag("Enemy") != null) { EnemyDamage enemyDamage = GameObject.FindWithTag("Enemy").GetComponent <EnemyDamage>(); if (enemyDamage.frozen == true) { enemyDamage.comboDamageAmount = enemyDamage.projectileDamageAmount * 2; enemyDamage.health -= enemyDamage.comboDamageAmount; } } } }
public void Fire() { if (!GameManager.instance.isGameover) { RaycastHit hit; if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit)) { if (hit.transform.tag == "Enemy" || hit.transform.name == "balloon1(Clone)" || hit.transform.name == "balloon2(Clone)" || hit.transform.name == "balloon3(Clone)") { EnemyDamage e = hit.collider.GetComponent <EnemyDamage>(); e.Damage(); //Destroy(hit.transform.gameObject, 2f); Instantiate(smoke, hit.point, Quaternion.LookRotation(hit.normal)); } else { Instantiate(gunshoot, hit.point, Quaternion.LookRotation(hit.normal)); } } } }
// Use this for initialization void Start() { animator = GetComponent <Animator>(); rig = GetComponent <Rigidbody>(); playerHitbox = GetComponent <EnemyDamage>(); bool initialized = false; FighterSetup[] setups = FindObjectsOfType <FighterSetup>(); if (setups.Length > 0) { foreach (FighterSetup setup in setups) { if ((playerID == 1 && setup.name == "Player1") || (playerID == 2 && setup.name == "Player2")) { InitializeFromSetup(setup); initialized = true; } } } if (!initialized) { Debug.Log("No setup for Player " + playerID + ". Using public variables."); animator.SetInteger("Jab_1_Num", jab_1_num); animator.SetInteger("Jab_2_Num", jab_2_num); animator.SetInteger("Jab_3_Num", jab_3_num); animator.SetInteger("Up_Air_Num", up_air_num); animator.SetInteger("Down_Air_Num", down_air_num); animator.SetInteger("Up_Tilt_Num", up_tilt_num); } }
private void OnTriggerEnter2D(Collider2D collision) { enemyDamage = collision.GetComponent <EnemyDamage>(); //Comprueba que el enemigo no está en el array de los que ya han sido atacados int i = 0; while (i < contEnem && collision.gameObject != enemies[i]) { i++; } if (enemyDamage != null && i == contEnem) { //Añade el enemigo al array de enemigos golpeados enemies[contEnem] = collision.gameObject; contEnem++; enemyDamage.TakeDamage(damage); SoundManager.Instance.Play(sfx); //Transform del padre que indica la dirección del ataque Transform directionTransform = transform.parent.parent; //Vector de la dirección hacia el enemigo Vector2 dir = collision.transform.position - directionTransform.position; //Knockback Vector2 dirKnockback = dir.normalized * knockbackForce; enemyDamage.Knockback(dirKnockback, knockbackTime); } }
private void Awake() { if (instance == null) { instance = this; } }
void OnTriggerEnter2D(Collider2D hitInfo) { //Debug.Log(hitInfo.name); EnemyDamage EnemyDamage = hitInfo.GetComponent <EnemyDamage>(); if (hitInfo.name != "Bullet(Clone)") { if (sourceOfShot == true) { Debug.Log("Invoking EnemyDamage Subroutine"); damage = Random.Range(30, 40); EnemyDamage.TakeDamage(damage); sourceOfShot = false; } else { Debug.Log("Invoking PlayerDamage Subroutine"); damage = Random.Range(10, 20); Health.TakeDamage(damage); } Destroy(gameObject); } else { Destroy(gameObject); } }
void Shoot() { MuzzleFlash.Play(); // script to play muzzle flash when you shoot RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) //This part is the actual Raycast part it turns the fpsCam into a position and then takes the fpsCam again and makes it so it's the forward part and then shoots a Ray to another hit box { Debug.Log(hit.transform.name); // just debug to see if gun was working EnemyDamage EnemyDamage = hit.transform.GetComponent <EnemyDamage>(); if (EnemyDamage != null) // this is saying if the enemy is taking Enemydamage to make them take damage { EnemyDamage.TakeDamage(damage); } if (hit.rigidbody != null) //This is adding knockback to what gets hit by guns { hit.rigidbody.AddForce(-hit.normal * ImpactForce); //-hit means they are getting hit backwards which is them multiplied by the impact force } Instantiate(ImpactEffect, hit.point, Quaternion.LookRotation(hit.normal)); // This is adding the bullet rickechy off ground and other surfaces (the look rotation is to make the animation play facing outwards instead of inwards towards the object) } }
void DoExplosion(Vector3 explosionPoint) { hitColliders = Physics.OverlapSphere(explosionPoint, blastRadius); foreach (Collider hitcol in hitColliders) { //Debug.Log(hitcol.gameObject.name); if (hitcol.GetComponent <Rigidbody>() != null) { if (hitcol.gameObject.tag == "Enemy") { EnemyDamage e = hitcol.GetComponent <EnemyDamage>(); e.ExDamage(); } if (hitcol.gameObject.tag == "Tank") { TankDamage t = hitcol.GetComponent <TankDamage>(); t.ExDamage(); } hitcol.GetComponent <Rigidbody>().isKinematic = false; hitcol.GetComponent <Rigidbody>().AddExplosionForce(explosionForce, explosionPoint, blastRadius, .005f, ForceMode.Impulse); Destroy(gameObject); } } }
public virtual IEnumerator DidPunch() { this.anim.CrossFadeQueued("punch", 0.1f, QueueMode.PlayNow); yield return(new WaitForSeconds(this.punchHitTime)); Vector3 pos = this.transform.TransformPoint(this.punchPosition); GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject go in enemies) { EnemyDamage enemy = (EnemyDamage)go.GetComponent(typeof(EnemyDamage)); if (enemy == null) { continue; } if (Vector3.Distance(enemy.transform.position, pos) < this.punchRadius) { enemy.SendMessage("ApplyDamage", this.punchHitPoints); if (this.punchSound) { this.GetComponent <AudioSource>().PlayOneShot(this.punchSound); } } } yield return(new WaitForSeconds(this.punchTime - this.punchHitTime)); this.busy = false; }
void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") { EnemyDamage ed = other.gameObject.GetComponent <EnemyDamage>(); //ed.KnockDown(); } }
// Use this for initialization void Start() { Pathfinder pathfinder = FindObjectOfType <Pathfinder>(); var path = pathfinder.GetPath(); StartCoroutine(FollowPath(path)); selfDestructSequence = GetComponent <EnemyDamage>(); }
// Update is called once per frame void Start() { mSight = GetComponent<EnemySight>(); mBehaviouir = new WonderState(); monkeyAudioSource = GetComponent<AudioSource>(); damage = new MonkeyDamage( this,materialEffect ); }
// Start is called before the first frame update void Start() { //roar = true; enemyDamage = GetComponent <EnemyDamage>(); enemyAttack = GetComponent <MinotaurAttack>(); target = PlayerManager.instance.player.transform; agent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator>(); }
// Start is called before the first frame update void Start() { collider = GetComponent <Collider>(); enemyDamage = GetComponent <EnemyDamage>(); target = PlayerManager.instance.player.transform; agent = GetComponent <NavMeshAgent>(); enemyAttack = GetComponent <EnemyAttack>(); animator = GetComponent <Animator>(); }
public Entity(int eEXP, EnemyHealth eHealth, EnemyDamage eDamage, int eX, int eY) //Default struct for enemy instance { Class = ClassID.None; EXP = eEXP; Health = eHealth; Damage = eDamage; X = eX; Y = eY; }
private void OnTriggerEnter2D(Collider2D collision) { EnemyDamage enemy = collision.GetComponent <EnemyDamage>(); if (enemy != null) { enemy.TakeDamage(DMG); } Destroy(gameObject); }
void Start() { healthDisplay = FindObjectOfType <HealthDisplay>(); enemyDamage = GetComponent <EnemyDamage>(); friendlyBase = FindObjectOfType <FriendlyBase>(); Pathfinder pathfinder = FindObjectOfType <Pathfinder>(); var path = pathfinder.GetPath(); StartCoroutine(FollowPath(path)); }
/* * The Start function: * Use GetComponent to get the rigidbody reference * Create a new Vector3 value for the direction variable with X and Z being zero and Y being a Random number between 0 and 360. * Assign the direction to the eulerAngles of this GameObject in order to rotate this GameObject */ void Start () { player = GameObject.FindGameObjectWithTag ("Player"); Dang = GetComponent<EnemyDamage> (); goat = GetComponent<Rigidbody>(); if (Dang.Type == EnemyDamage.Badguys.Enemy) { direction = new Vector3(0, Random.Range(0, 360), 0); transform.eulerAngles = direction; } }
// Start is called before the first frame update void Start() { combatState = GameObject.Find("GM").GetComponent <CombatState>(); roar = true; enemyDamage = GetComponent <EnemyDamage>(); enemyAttack = GetComponent <GolemAttack>(); target = PlayerManager.instance.player.transform; agent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator>(); }
void OnTriggerEnter2D(Collider2D otherCollider) { EnemyDamage enemy = otherCollider.gameObject.GetComponent <EnemyDamage>(); if (enemy != null) { Damage(enemy.damage); Destroy(enemy.gameObject); } }
void Start() { waveController = GameObject.FindWithTag("World").GetComponent <WaveController>(); playerHealth = GameObject.FindWithTag("Player").GetComponent <PlayerHealth>(); enemyDamage = GameObject.FindWithTag("Enemy").GetComponent <EnemyDamage>(); PathFinder pathFinder = FindObjectOfType <PathFinder>(); List <Waypoint> path = pathFinder.GetPath(); StartCoroutine(FollowPath(path)); }
/* * The Start function: * Use GetComponent to get the rigidbody reference * Create a new Vector3 value for the direction variable with X and Z being zero and Y being a Random number between 0 and 360. * Assign the direction to the eulerAngles of this GameObject in order to rotate this GameObject */ void Start() { var1 = GetComponent<Rigidbody>(); player = GameObject.FindGameObjectWithTag("Player"); enmeDamage = GetComponent<EnemyDamage>(); if (enmeDamage.myEnemy == EnemyDamage.Enemies.Weak) { Vector3 direction1 = new Vector3(0, Random.Range(0, 360), 0); transform.eulerAngles = direction1; } }
void Start() { player = GameObject.FindGameObjectWithTag ("Player"); dmg = GetComponent<EnemyDamage> (); rigidbody = gameObject.GetComponent<Rigidbody> (); if (dmg.enemyType == EnemyDamage.Enemies.SQUARE) { dir = new Vector3 (0, Random.Range (0, 360), 0); } transform.eulerAngles = dir; }