void OnChildTriggerEnter(Collider myCol) { //print ("on trigger"); if (myCol.gameObject.GetComponent <Health>()) { //print ("found helath component"); Health dealtarget = myCol.gameObject.GetComponent <Health>(); dealtarget.Damage(damage, transform); } Hp leDealTarget = null; if (myCol.GetComponent <Hp> ()) { leDealTarget = myCol.GetComponent <Hp> (); } else if (myCol.GetComponentInChildren <Hp> ()) { leDealTarget = myCol.GetComponentInChildren <Hp> (); } else if (myCol.GetComponentInParent <Hp> ()) { leDealTarget = myCol.GetComponentInParent <Hp> (); } if (leDealTarget != null) { leDealTarget.Damage((int)((float)damage * friendlyFireMultiplier)); } }
private void OnTriggerEnter2D(Collider2D hitInfo)//ด้านดาเมจ { Hp enemy = hitInfo.GetComponent <Hp>(); if (enemy != null) { enemy.Damage(damage); } Destroy(gameObject); }
void Explode() { float distance = Vector3.Distance(GameObject.FindGameObjectWithTag("Player").transform.position, transform.position); //explosion Vector3 explosionPos = transform.position; Collider[] colliders = Physics.OverlapSphere(explosionPos, radious); foreach (Collider hit in colliders) { if (hit != null && hit.GetComponent <Rigidbody>() || hit.GetComponentInParent <Rigidbody>()) { if (hit.GetComponent <ExplosionAffection> ()) { hit.GetComponent <ExplosionAffection> ().GetEffected(); } else if (hit.GetComponentInParent <ExplosionAffection>()) { hit.GetComponentInParent <ExplosionAffection> ().GetEffected(); } if (hit.GetComponent <Rigidbody> ()) { hit.GetComponent <Rigidbody>().AddExplosionForce(power, explosionPos, radious, 3.0f); } else if (hit.GetComponentInParent <Rigidbody>()) { hit.GetComponentInParent <Rigidbody>().AddExplosionForce(power, explosionPos, radious, 3.0f); } } //deal damage if (distance < maxRange) { if (hit.GetComponent <Health>()) { Health dealtarget = hit.gameObject.GetComponent <Health>(); dealtarget.Damage((int)((float)expDamage * (1f - (distance / maxRange))), transform); if (dealtarget.health <= 0 && dealtarget.isAlive) { Instantiate(killerPrefab, transform.position, transform.rotation); } } } //deal damage to other enemies Hp leDealTarget = null; if (hit.GetComponent <Hp> ()) { leDealTarget = hit.GetComponent <Hp> (); } else if (hit.GetComponentInChildren <Hp> ()) { leDealTarget = hit.GetComponentInChildren <Hp> (); } else if (hit.GetComponentInParent <Hp> ()) { leDealTarget = hit.GetComponentInParent <Hp> (); } if (leDealTarget != null) { float leDistance = Vector3.Distance(transform.position, hit.gameObject.transform.position); leDealTarget.Damage((int)(Mathf.Clamp(((float)expDamage * friendlyFireMultiplier * (1f - (leDistance / maxRange))), 0, expDamage))); } } //other stuff Rigidbody zomIns; GameObject myExp = (GameObject)Instantiate(exp, transform.position, transform.rotation); myExp.GetComponent <UnityStandardAssets.Effects.ParticleSystemMultiplier> ().multiplier = 0.5f; zomIns = (Rigidbody)Instantiate(kafa, transform.position + new Vector3(0, 1, 0), transform.rotation); zomIns.AddRelativeForce(0, 500, 0); zomIns.AddRelativeTorque(Random.Range(15, 100), Random.Range(15, 100), Random.Range(15, 100)); Destroy(gameObject); }
void Explode() { //explosion Vector3 explosionPos = transform.position; Collider[] colliders = Physics.OverlapSphere(explosionPos, radious); foreach (Collider hit in colliders) { if (hit != null && hit.GetComponent <Rigidbody>() || hit.GetComponentInParent <Rigidbody>()) { if (hit.GetComponent <ExplosionAffection> ()) { hit.GetComponent <ExplosionAffection> ().GetEffected(); } else if (hit.GetComponentInParent <ExplosionAffection>()) { hit.GetComponentInParent <ExplosionAffection> ().GetEffected(); } if (hit.GetComponent <Rigidbody> ()) { hit.GetComponent <Rigidbody>().AddExplosionForce(power, explosionPos, radious, 3.0f); } else if (hit.GetComponentInParent <Rigidbody>()) { hit.GetComponentInParent <Rigidbody>().AddExplosionForce(power, explosionPos, radious, 3.0f); } } //deal damage if (distance < maxRange) { if (hit.GetComponent <Health>()) { Health dealtarget = hit.gameObject.GetComponent <Health>(); dealtarget.Damage((int)((float)damage * (1f - (distance / maxRange))), transform); if (dealtarget.health <= 0 && dealtarget.isAlive) { Instantiate(killerPrefab, transform.position, transform.rotation); } } } //deal damage to other enemies Hp leDealTarget = null; if (hit.GetComponent <Hp> ()) { leDealTarget = hit.GetComponent <Hp> (); } else if (hit.GetComponentInChildren <Hp> ()) { leDealTarget = hit.GetComponentInChildren <Hp> (); } else if (hit.GetComponentInParent <Hp> ()) { leDealTarget = hit.GetComponentInParent <Hp> (); } if (leDealTarget != null) { float leDistance = Vector3.Distance(transform.position, hit.gameObject.transform.position); leDealTarget.Damage((int)(Mathf.Clamp(((float)damage * friendlyFireMultiplier * (1f - (leDistance / maxRange))), 0, Mathf.Infinity))); } } //other stuff Rigidbody zomIns; GameObject myExp = (GameObject)Instantiate(exp, transform.position, transform.rotation); myExp.GetComponent <UnityStandardAssets.Effects.ParticleSystemMultiplier> ().multiplier = 0.5f; zomIns = (Rigidbody)Instantiate(kafa, transform.position + new Vector3(0, 1, 0), transform.rotation); zomIns.AddRelativeForce(0, 500, 0); zomIns.AddRelativeTorque(Random.Range(15, 100), Random.Range(15, 100), Random.Range(15, 100)); //item drop //int randomChance = (int)Random.Range(0, itemDropChance); //print(randomChance); if (/*randomChance == 0*/ LootCounter.ShouldDropLoot(level)) { Debug.LogWarning("item dropped"); GameObject myItem = (GameObject)Instantiate(itemDrop, transform.position + Vector3.up, transform.rotation); myItem.GetComponent <GunDrop>().MakeGun(level, rarity); } //give xp int xpToGive = xp + Random.Range(-xpRange, xpRange); XpGiver.giveXp(xpToGive); ScoreController.myScore.AddScore((int)((float)xpToGive * Random.Range(1f, Mathf.Sqrt((float)level)))); Destroy(gameObject); }
// Update is called once per frame void Shoot() { //MuzzleEffect.SetupPool (); // The Ray-hits will be in a circular area float randomRadius = Random.Range(0f, (float)val.accuracy); float randomAngle = Random.Range(0f, 2f * Mathf.PI); //Calculating the raycast direction Vector3 direction = new Vector3( randomRadius * Mathf.Cos(randomAngle), randomRadius * Mathf.Sin(randomAngle), z ); //Make the direction match the transform //It is like converting the Vector3.forward to transform.forward direction = val.myBulletSource.TransformDirection(direction.normalized); //Raycast and debug Ray r = new Ray(val.myBulletSource.position, direction); RaycastHit hit; int layerMask = 1 << 9; if (val.isPlayer) { layerMask = 511; } if (Physics.Raycast(r, out hit, Mathf.Infinity, layerMask)) { //deal damage //if (hit.collider.gameObject.tag == "Enemy") { Hp hp = hit.collider.gameObject.GetComponent <Hp> (); if (hp == null) { hp = hit.collider.gameObject.GetComponentInParent <Hp> (); } if (hp == null) { hp = hit.collider.gameObject.GetComponentInChildren <Hp> (); } if (hp != null) { hp.Damage(val.damage); } Health health = hit.collider.gameObject.GetComponent <Health> (); if (health == null) { health = hit.collider.gameObject.GetComponentInParent <Health> (); } if (health == null) { health = hit.collider.gameObject.GetComponentInChildren <Health> (); } if (health != null) { health.Damage(val.damage, transform); } //} /* * if (your.bacı == false) { * set.anan = true * } */ //decals if (!health && hit.collider.gameObject.tag != "GunDrop") { GameObject myDecal = (GameObject)Instantiate(bulletHoleDecal, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); myDecal.transform.parent = hit.collider.gameObject.transform; } } else { hit.point = (r.direction * 20) + r.origin; } //------------------------- //gfc Debug.DrawLine(val.barrelPoint.position, hit.point); if (myLine) { myLine.enabled = true; myLine.SetPosition(0, val.barrelPoint.position); myLine.SetPosition(1, hit.point); Invoke("RemoveLine", 0.1f); } //MuzzleEffect.ShowMuzzleEffect(val.barrelPoint.transform, true, Audio); Instantiate(muzzleEffect, val.barrelPoint.position, val.barrelPoint.rotation); //---------------------------------------- }