public void ShootAmmo(float aimAngle) { GameObject spawnedAmmo = Instantiate(ammo); spawnedAmmo.transform.position = CustomFunctions.GetAmmoSpawnPos(playerController.gameObject); spawnedAmmo.transform.rotation = Quaternion.Euler(0, 0, aimAngle * Mathf.Rad2Deg); AmmoVelocity ammoVelocity = spawnedAmmo.GetComponent <AmmoVelocity>(); ammoVelocity.direction = Vector2.right; ammoVelocity.speed = GameManager.instance.GetPlayerWeapon(playerController.gameObject).ammoVelocity; DamageZone ammoDamage = spawnedAmmo.GetComponent <DamageZone>(); ammoDamage.ignorePlayer = playerController.gameObject; ammoDamage.playerThatShotThis = playerController.gameObject; ammoDamage.damage = GameManager.instance.GetPlayerWeapon(playerController.gameObject).damage; ammoDamage.destroyOnWallCollision = destroyAmmoOnWallCollision; ammoDamage.destroyOnPlayerCollision = true; CustomFunctions.SetTrailColor(spawnedAmmo.GetComponent <TrailRenderer>(), GameManager.instance.GetPlayerId(playerController.gameObject)); Physics2D.IgnoreCollision(spawnedAmmo.GetComponent <Collider2D>(), playerController.GetComponent <Collider2D>()); Destroy(spawnedAmmo, 10f); }
void Shoot() { if (GameManager.instance.isInWeaponSelection == true) { return; } GameObject spawnedAmmo = Instantiate(bulletPrefab); spawnedAmmo.transform.position = transform.position; float angle = Vector2.Angle(GetAmmoDirection(), Vector2.left) + +180f; if (transform.position.y < currentTargetPosition.y) { angle = -angle; } spawnedAmmo.transform.rotation = Quaternion.Euler(0, 0, angle); spawnedAmmo.GetComponent <AmmoVelocity>().direction = Vector2.right; spawnedAmmo.GetComponent <AmmoVelocity>().speed = 20f; DamageZone ammoDamage = spawnedAmmo.GetComponent <DamageZone>(); ammoDamage.ignorePlayer = this.gameObject; ammoDamage.damage = damage; ammoDamage.destroyOnWallCollision = true; ammoDamage.destroyOnPlayerCollision = true; ammoDamage.ignoreLayer = ignoreLayerBullets; spawnedAmmo.GetComponent <TrailRenderer>().startColor = Color.white; spawnedAmmo.layer = this.gameObject.layer; }
int ExplosionRay(Vector3 ringDir) { int simulation = -1; Vector3 pos = transform.position + (transform.forward * 0.125f); if (Physics.Raycast(pos, ringDir, out var hit, (radius - 0.125f))) { float dmg = Damage / (float)hitsForFullDmg; float dis = Vector3.Distance(hit.point, pos) + 0.05f; Rigidbody body = null; if ((body = hit.transform.GetComponent <Rigidbody>()) != null) { body.AddForceAtPosition(ringDir * dmg, hit.point, ForceMode.Force); } if (Physics.Raycast(pos, ringDir, out var hitDmg, dis, damageLayer)) { Debug.DrawRay(pos, ringDir * dis, Color.red); DamageZone damaged = hitDmg.transform.GetComponent <DamageZone>(); if (damaged != null) { simulation = Mathf.Max(simulation, 0); if (damaged.Damage(dmg, 1f)) { simulation = 1; } } } } return(simulation); }
private void Start() { if (GameManager.instance.isInOnlineMultiplayer == false) { this.enabled = false; return; } damageScript = GetComponent <DamageZone>(); velocityScript = GetComponent <AmmoVelocity>(); print(damageScript.playerThatShotThis); if (damageScript.playerThatShotThis == NetworkPlayer.localPlayer.gameObject) //this means that we spawned this bullet locally { GetSettings(); NetworkPlayer.localPlayer.CmdSpawnBullet(bulletId, NetworkPlayer.localPlayer.gameObject, settings); } else //this bullet has just been spawned from the server { damageScript.dontDoDamage = true; //the damage has already been taken care of if (settings.playerWhoSpawnedThis == NetworkPlayer.localPlayer.gameObject) { this.gameObject.SetActive(false); return; } SetSettings(); } }
public virtual int Simulate() { int simulation = -1; Vector3 dir = -transform.forward; Vector3 pos = transform.position + (transform.forward * 0.125f); if (Physics.Raycast(pos, dir, out var hit, 0.175f)) { parentAdjuster = new GameObject().transform; parentAdjuster.position = hit.point; parentAdjuster.SetParent(hit.transform); transform.SetParent(parentAdjuster); float dis = Vector3.Distance(hit.point, pos) + 0.05f + size; if (Physics.SphereCast(pos, size, dir, out var hitDmg, dis, damageLayer)) { DamageZone damaged = hitDmg.transform.GetComponent <DamageZone>(); if (damaged != null) { if (!damaged.DamageableAlreadyDead()) { simulation = Mathf.Max(simulation, 0); if (damaged.Damage(Damage, 1f)) { simulation = 1; } } } } } return(simulation); }
IEnumerator StartSetZoneActive(int _zoneInd, string _zoneName, bool _active, float _time, float _delay) { DamageZone zone = null; if (_zoneName != null) { zone = FindZoneByName(_zoneName); } else { zone = zones[_zoneInd]; } //delay float timer = 0; while (timer < _delay) { timer += Time.deltaTime; yield return(new WaitForEndOfFrame()); } zone.active = _active; //active Time timer = 0; while (timer < _time) { timer += Time.deltaTime; yield return(new WaitForEndOfFrame()); } zone.active = !_active; }
IEnumerator StartSetZoneActive(int _zoneInd, string _zoneName, bool _active, int _framesActive, int _frameDelay) { DamageZone zone = null; if (_zoneName != null) { zone = FindZoneByName(_zoneName); } else { zone = zones[_zoneInd]; } int delay = 0; while (delay < _frameDelay) { delay++; yield return(new WaitForEndOfFrame()); } zone.active = _active; int active = 0; while (active < _framesActive) { active++; yield return(new WaitForEndOfFrame()); } zone.active = !_active; }
void Awake() { bossContainer = transform.parent.gameObject; player = GameObject.FindGameObjectWithTag("Player"); bossContainerAnimator = bossContainer.GetComponent <Animator>(); fixedVirtualCameraAnimator = fixedVirtualCamera.GetComponent <Animator>(); fxPlayerAudioSource = fxPlayer.GetComponent <AudioSource>(); damageZoneScript = damageZone.GetComponent <DamageZone>(); }
void Start() { timerCD = 0; damageZone = GetComponentInChildren <DamageZone>(); damageZone.damage = DMG; damageZone.targetTag = TargetTag.Enemy; damageZoneObject = damageZone.gameObject; damageZone.gameObject.SetActive(false); }
void Start() { rigidbodyParent = transform.parent.GetComponent <Rigidbody>(); damageZone = GetComponentInChildren <DamageZone>(); damageZone.damage = DMG; damageZone.targetTag = TargetTag.Enemy; damageZoneObject = damageZone.gameObject; damageZone.gameObject.SetActive(false); }
void Start() { cooldownTime = cooldown; cooldown = 0; damageZone = GetComponentInChildren <DamageZone>(); damageZone.damage = DMG; damageZone.targetTag = TargetTag.Player; damageZoneObject = damageZone.gameObject; damageZone.gameObject.SetActive(false); }
public IEnumerator BigChungusAttack() { isBusy = true; DamageZone damageZone = Instantiate(attackPrefab, transform.position, transform.rotation).GetComponent <DamageZone>(); damageZone.damage = damage; yield return(new WaitForSeconds(strikeDelay)); isBusy = false; isAttacking = false; }
protected void UpdateZoneDamage() { if (!ReceiveZoneDamage) { return; } if (Health == null) { Health = GetComponent <DamageReceiver>(); } DamageZone.ApplyDamage(Health); }
private void Awake() { instance = this; circleTransform = transform.Find("circle"); topTransform = transform.Find("top"); bottomTransform = transform.Find("bottom"); leftTransform = transform.Find("left"); rightTransform = transform.Find("right"); SetCircleSize(new Vector3(0, 0), new Vector3(20, 20)); SetTargetCircle(new Vector3(0, 0), new Vector3(15, 15), 3f); }
void Start() { player = GameObject.FindGameObjectWithTag("Player"); animatorComponent = GetComponent <Animator>(); rightDamageZoneScript = rightDamageZone.GetComponent <DamageZone>(); leftDamageZoneScript = leftDamageZone.GetComponent <DamageZone>(); lifeSystemScript = player.GetComponent <LifeSystem>(); playerRigidbody = player.GetComponent <Rigidbody2D>(); playerMovementScript = player.GetComponent <PlayerMovement>(); dashZoneScript = dashZone.GetComponent <DashZone>(); popup.SetActive(true); StartCoroutine("States", "Start"); }
public IEnumerator TestDeadPlyerStopTime() { GameObject GO_player = CreatePlayer(0, 1, 0); Player player = GO_player.GetComponent <Player>(); GameObject GO_damageZone = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Test/DamageZone 1"), new Vector3(0, 0, 0), Quaternion.identity); DamageZone damageZone = GO_damageZone.GetComponent <DamageZone>(); damageZone.damage = 3; yield return(new WaitForSecondsRealtime(player.TimeToDeadScreen + 0.1f)); Assert.AreEqual(0, Time.timeScale); }
public IEnumerator TestDeadEnemy() { GameObject GO_enemy = CreateEnemy(0, 1, 0); GameObject GO_damageZone = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Test/DamageZone 1"), new Vector3(0, 0, 0), Quaternion.identity); DamageZone damageZone = GO_damageZone.GetComponent <DamageZone>(); damageZone.targetTag = TargetTag.Enemy; damageZone.damage = 3; yield return(new WaitForSeconds(1.1f)); UnityEngine.Assertions.Assert.IsNull(GO_enemy); }
public IEnumerator TestDamageEnemy() { GameObject GO_enemy = CreateEnemy(0, 1, 0); Enemy enemy = GO_enemy.GetComponent <Enemy>(); GameObject GO_damageZone = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Test/DamageZone 1"), new Vector3(0, 0, 0), Quaternion.identity); DamageZone damageZone = GO_damageZone.GetComponent <DamageZone>(); damageZone.targetTag = TargetTag.Enemy; yield return(new WaitForSeconds(0.1f)); Assert.AreEqual(2, enemy.HP); }
public IEnumerator TestDamagePlayer() { GameObject GO_player = CreatePlayer(0, 1, 0); Player player = GO_player.GetComponent <Player>(); GameObject GO_damageZone = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Test/DamageZone 1"), new Vector3(0, 0, 0), Quaternion.identity); DamageZone damageZone = GO_damageZone.GetComponent <DamageZone>(); damageZone.targetTag = TargetTag.Player; damageZone.damage = 1; yield return(new WaitForSeconds(0.1f)); Assert.AreEqual(2, player.HP); }
void RaycastShot() { Transform camera = cameraMovement.transform; //Shoot from camera, not gun GunObject gun = gunHandler.gun; Vector3 shotDir = getShotDir(bulletSpread); Vector3 worldDir = camera.TransformDirection(shotDir); Vector3 impactPos = camera.position; impactPos += worldDir * gun.bulletRange; Ray shotRay = new Ray(camera.position, worldDir); if (Physics.Raycast(shotRay, out var hit, gun.bulletRange, collisionLayer)) { DamageZone damaged = null; float dis = Vector3.Distance(camera.position, hit.point) + 0.05f; if (Physics.Raycast(shotRay, out var dmg, dis, damageLayer)) { damaged = dmg.transform.GetComponent <DamageZone>(); } impactPos = hit.point; CreateImpact(impactPos, hit.normal); if (damaged != null) //If we hit something we should damage { if (!damaged.DamageableAlreadyDead()) { bool killed = damaged.Damage(gun.bulletDamage, gun.headshotMult); if (ui) { ui.ShowHitmarker(killed); //Damages and shows hitmarker } } } } Vector3[] pos = { gunHandler.bulletSpawn.transform.position, impactPos }; ShotTrailHelper trail = helper.getAvailableTrail(); trail.Initialize(pos); }
// Start is called before the first frame update void Start() { damageZone = GetComponent <DamageZone>(); arayaHp = GetComponent <EnemyHealth>(); arayaAnim = GetComponent <Animator>(); arayaShock = GetComponent <SpriteRenderer>(); cansZone = transform.GetChild(0).GetComponent <DamageZone>(); cansAnim = transform.GetChild(0).GetComponent <Animator>(); beamLocations = new Vector3[11]; beamLocations[0] = new Vector3(-7100, -4066, 0); beamLocations[1] = new Vector3(-7069, -4066, 0); beamLocations[2] = new Vector3(-7038, -4066, 0); beamLocations[3] = new Vector3(-7007, -4066, 0); beamLocations[4] = new Vector3(-6976, -4066, 0); beamLocations[5] = new Vector3(-6945, -4066, 0); beamLocations[6] = new Vector3(-6914, -4066, 0); beamLocations[7] = new Vector3(-6883, -4066, 0); }
public void RefreshTargets() { targetZones.Clear(); foreach (var damageZone in playerController.DamageColliders) { Transform target = damageZone.transform; Vector3 directionToTarget = (target.position - transform.position).normalized; if (Physics.Raycast(transform.position, directionToTarget, out rayHit, playerDistance, targetLayer)) { DamageZone temp = rayHit.transform.GetComponent <DamageZone>(); if (currentTarget == null) { currentTarget = temp; return; } if (temp.Priority < currentTarget.Priority) { currentTarget = temp; } } } }
void Start() { damageZone = GetComponent <DamageZone>(); m_Rigidbody = GetComponent <Rigidbody>(); }
private void Start() { ammoDamageZone = GetComponent <DamageZone>(); ammoVelocity = GetComponent <AmmoVelocity>(); ammoDamageZone.OnWallCollision += BounceAmmo; }
//diese Methode sorgt dafür, dass das Auto einen Reifen verliert private void loseAWheel(DamageZone damZone) { Wheel wheelToDestroy = null; hasLostWheel = true; //gehe durch jedes Rad durch und such dasd richtige raus foreach(Wheel wheel in wheels) { if(wheel.damageZone == damZone) { wheelToDestroy = wheel; break; } } //call by reference durch ref if(wheelToDestroy != null) { removeWheelFromList(ref wheelToDestroy); } }
//// SCHADENSMODELLE AUFSETZEN, EXPLODIEREN //diese Methode behandelt den Schaden der einzelnen DestructibleCarParts public void applyDamage(DamageZone damZone, float damageAmount) { health -= damageAmount; //die Scheiben sollen als erstes kaputt gehen if(health < 90) { glassDamageModels[0].SetActive(false); glassDamageModels[1].SetActive(true); } //für den sichtbaren Schaden sind keine float Werte nötig, 4 ist da um den Sichtbaren Schaden deutlicher zu machen applyVisualDamage(damZone, (int)damageAmount * 4); //Wenn die Lebenspunkte 0 sind, soll das Auto explodieren und alle refen verlieren if(health<=0.0f) { explodeCar(); } }
public void SyncGames(MTSyncGame sync) { // Sync projectiles for (int i = 0; i < sync.NumProjectiles; i++) { Projectile p = FindProjectileByID(sync.ProjectileIDs[i]); if (p) { p.transform.position += (sync.ProjectilePositions[i] - p.transform.position) * 0.5f; p.transform.rotation = Quaternion.Lerp(p.transform.rotation, Quaternion.Euler(sync.ProjectileRotations[i]), 0.5f); p.Velocity = Vector3.Lerp(p.Velocity, sync.ProjectileVelocities[i], 0.5f); } else { Debug.LogWarning("Sync projectile: could not find id " + sync.ProjectileIDs[i]); } } // Sync ships uint waterIngressSectionsCounter = 0; uint gunTurretsCounter = 0; uint damageZoneCounter = 0; uint damageZoneDamagesCounter = 0; for (int i = 0; i < sync.NumShips; i++) { Ship s = FindShipByID(sync.ShipIDs[i]); bool counterUpdated = false; if (s != null && !s.Equals(null)) { if (sync.ShipsHitpoints[i] <= 0 && !s.Destroyed) { s.DamageHull(float.MaxValue); } else if (!s.Destroyed) { s.HullHitpoints = Mathf.Lerp(s.HullHitpoints, sync.ShipsHitpoints[i], 0.5f); s.transform.position += (sync.ShipPositions[i] - s.transform.position) * 0.5f; s.transform.rotation = Quaternion.Lerp(s.transform.rotation, Quaternion.Euler(sync.ShipRotations[i]), 0.5f); s.Velocity = Vector3.Lerp(s.Velocity, sync.ShipVelocities[i], 0.5f); for (byte waterIngressSectionIndex = 0; waterIngressSectionIndex < sync.ShipsNumWaterIngressSections[i]; waterIngressSectionIndex++) { Ship.WaterIngressSection section = s.WaterIngressSections.Find(wis => wis.sectionID == sync.WaterIngressSectionsIDs[waterIngressSectionsCounter]); section.numHoles = Mathf.CeilToInt(Mathf.Lerp(section.numHoles, sync.WaterIngressNumHoles[waterIngressSectionsCounter], 0.5f)); section.waterLevel = Mathf.Lerp(section.waterLevel, sync.WaterIngressWaterLevels[waterIngressSectionsCounter++], 0.5f); } if (s.PlayerTag != thisPlayerTag) { s.Autopilot.Chadburn = sync.ShipChadburnSettings[i]; s.Autopilot.Course = sync.ShipCourses[i]; if (sync.ShipsHasTarget[i]) { s.Targeting.Target = FindShipByID(sync.ShipsTargetShipID[i]); } else { s.Targeting.Target = null; } } for (byte gunTurretIndex = 0; gunTurretIndex < sync.ShipsNumGunTurrets[i]; gunTurretIndex++) { GunTurret t = s.Armament.GunTurrets.Find(gt => gt.ID == sync.GunTurretIDs[gunTurretsCounter]); if (sync.GunTurretsDisabled[gunTurretsCounter]) { t.Disable(); } t.ReloadProgress = Mathf.Lerp(t.ReloadProgress, sync.GunTurretsReloadProgress[gunTurretsCounter], 0.5f); t.TurretRotation = Mathf.Lerp(t.TurretRotation, sync.GunTurretsRotation[gunTurretsCounter], 0.5f); t.TargetTurretRotation = Mathf.Lerp(t.TargetTurretRotation, sync.GunTurretsTargetRotation[gunTurretsCounter], 0.5f); t.GunsElevation = Mathf.Lerp(t.GunsElevation, sync.GunTurretsElevation[gunTurretsCounter], 0.5f); t.TargetGunsElevation = Mathf.Lerp(t.TargetGunsElevation, sync.GunTurretsTargetElevation[gunTurretsCounter], 0.5f); t.StabilizationAngle = Mathf.Lerp(t.StabilizationAngle, sync.GunTurretsStabilizationAngle[gunTurretsCounter++], 0.5f); } for (byte damageZoneIndex = 0; damageZoneIndex < sync.ShipNumDamageZones[i]; damageZoneIndex++) { DamageZone dz = s.DamageZones.Find(sdz => sdz.ID == sync.ShipDamageZoneIDs[damageZoneCounter]); for (byte damageIndex = 0; damageIndex < sync.DamageZoneNumDamages[damageZoneCounter]; damageIndex++) { DamageType dt = sync.DamageZoneDamages[damageZoneDamagesCounter++]; if (!dz.Damages.Contains(dt)) { dz.Damages.Add(dt); } } damageZoneCounter++; } counterUpdated = true; } } else { Debug.LogWarning("Sync ship: could not find id " + sync.ShipIDs[i]); } // Update counter in case they did not get updated inside the ifs if (!counterUpdated) { waterIngressSectionsCounter += sync.ShipsNumWaterIngressSections[i]; gunTurretsCounter += sync.ShipsNumGunTurrets[i]; for (int k = 0; k < sync.ShipNumDamageZones[i]; k++) { damageZoneDamagesCounter += sync.DamageZoneNumDamages[damageZoneCounter]; damageZoneCounter++; } } } }
//diese Methode verarbeitet den Schaden und schaut, aus welcher Richtung er kam und ruf entsprechende Methode auf private void applyVisualDamage(DamageZone damZone, int damageAmount) { //zunächst muss geschaut werden, an welcher Stelle der Schaden angerichtet werden soll switch (damZone) { case DamageZone.FRONT: setupFrontDamage(damageAmount); break; case DamageZone.REAR: setupRearDamage(damageAmount); break; case DamageZone.RIGHT: setupRightDamage(damageAmount); break; case DamageZone.LEFT: setupLeftDamage(damageAmount); break; case DamageZone.FRONT_LEFT: setupFrontLeftDamage(damageAmount); break; case DamageZone.FRONT_RIGHT: setupFrontRightDamage(damageAmount); break; case DamageZone.REAR_LEFT: setupRearLeftDamage(damageAmount); break; case DamageZone.REAR_RIGHT: setupRearRightDamage(damageAmount); break; } }