private void AttackPlayer() { state = State.Busy; Vector3 targetPosition = player.GetPosition(); Vector3 dirToTarget = (targetPosition - GetPosition()).normalized; lastMoveDir = dirToTarget; unitAnimation.PlayAnimForced(attackUnitAnim, dirToTarget, 2f, (UnitAnim unitAnim) => { // Attack complete if (player.IsDead()) { state = State.Moving; } else { state = State.AttackingPlayer; } }, (string trigger) => { // Damage Player player.Damage(this); }, null); Vector3 gunEndPointPosition = unitSkeleton.GetBodyPartPosition("MuzzleFlash"); Shoot_Flash.AddFlash(gunEndPointPosition); WeaponTracer.Create(gunEndPointPosition, player.GetPosition()); }
private void CharacterAimHandler_OnShoot(object sender, CharacterAimHandler.OnShootEventArgs e) { // Player shot weapon Shoot_Flash.AddFlash(e.gunEndPointPosition); WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition); UtilsClass.ShakeCamera(.6f, .05f); // Any enemy hit? RaycastHit2D raycastHit = Physics2D.Raycast(e.gunEndPointPosition, (e.shootPosition - e.gunEndPointPosition).normalized, Vector3.Distance(e.gunEndPointPosition, e.shootPosition)); if (raycastHit.collider != null) { EnemyHandler enemyHandler = raycastHit.collider.gameObject.GetComponent <EnemyHandler>(); if (enemyHandler != null) { // Hit enemy int damageAmount = UnityEngine.Random.Range(100, 200); bool isCritical = UnityEngine.Random.Range(0, 100) < 30; if (isCritical) { damageAmount *= 2; } // Deal damage enemyHandler.Damage(this, damageAmount); DamagePopup.Create(enemyHandler.GetPosition(), damageAmount, isCritical); } } }
private void CharacterAimBase_OnShoot(object sender, CharacterAim_Base.OnShootEventArgs e) { Shoot_Flash.AddFlash(e.gunEndPointPosition); WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition); UtilsClass.ShakeCamera(.6f, .05f); SpawnBulletShellCasing(e.gunEndPointPosition, e.shootPosition); if (weaponType == WeaponType.Shotgun) { // Shotgun spread int shotgunShells = 4; for (int i = 0; i < shotgunShells; i++) { WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition + UtilsClass.GetRandomDir() * Random.Range(-20f, 20f)); if (i % 2 == 0) { SpawnBulletShellCasing(e.gunEndPointPosition, e.shootPosition); } } } // Any enemy hit? RaycastHit2D raycastHit = Physics2D.Raycast(e.gunEndPointPosition, (e.shootPosition - e.gunEndPointPosition).normalized, Vector3.Distance(e.gunEndPointPosition, e.shootPosition)); if (raycastHit.collider != null) { EnemyHandler enemyHandler = raycastHit.collider.gameObject.GetComponent <EnemyHandler>(); if (enemyHandler != null) { Debug.Log("Cannot Damage!"); //enemyHandler.Damage(characterAimBase); } } }
private void ShootRaycast(Vector3 gunEndPointPosition, Vector3 shootPosition) { Vector3 shootDir = (shootPosition - gunEndPointPosition).normalized; BulletRaycast.Shoot(gunEndPointPosition, shootDir); WeaponTracer.Create(gunEndPointPosition, UtilsClass.GetMouseWorldPosition()); }
private void PlayerAimWeapon_OnShoot(object sender, PlayerAimWeapon.OnShootEventArgs e) { UtilsClass.ShakeCamera(.6f, .05f); WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition); Shoot_Flash.AddFlash(e.gunEndPointPosition); Vector3 shootDir = (e.shootPosition - e.gunEndPointPosition).normalized; shootDir = UtilsClass.ApplyRotationToVector(shootDir, 90f); ShellParticleSystemHandler.Instance.SpawnShell(e.shellPosition, shootDir); }
protected override void OnUpdate() { EntityQuery entityQuery = GetEntityQuery(typeof(Zombie)); int entityCount = entityQuery.CalculateEntityCount(); MarineShotZombieAction marineShotZombieAction; while (TestECS.queuedActions.TryDequeue(out marineShotZombieAction)) { if (EntityManager.Exists(marineShotZombieAction.marineEntity) && EntityManager.Exists(marineShotZombieAction.zombieEntity)) { float3 marinePosition = EntityManager.GetComponentData <Translation>(marineShotZombieAction.marineEntity).Value; float3 zombiePosition = EntityManager.GetComponentData <Translation>(marineShotZombieAction.zombieEntity).Value; float3 marineToZombieDir = math.normalize(zombiePosition - marinePosition); bool bonusEffects = (entityCount < 400 || UnityEngine.Random.Range(0, 100) < 60); if (bonusEffects) { WeaponTracer.Create(marinePosition + marineToZombieDir * 10f, (Vector3)zombiePosition + UtilsClass.GetRandomDir() * UnityEngine.Random.Range(0, 20f)); Shoot_Flash.AddFlash(marinePosition + marineToZombieDir * 14f); Blood_Handler.SpawnBlood(2, zombiePosition, marineToZombieDir); UtilsClass.ShakeCamera(TestECS.GetCameraShakeIntensity(), .05f); //Sound_Manager.PlaySound(Sound_Manager.Sound.Rifle_Fire, marinePosition); } Health zombieHealth = EntityManager.GetComponentData <Health>(marineShotZombieAction.zombieEntity); zombieHealth.health -= marineShotZombieAction.damageAmount; if (zombieHealth.health < 0) { // Zombie dead! FlyingBody.TryCreate(GameAssets.i.pfEnemyFlyingBody, zombiePosition, marineToZombieDir); EntityManager.DestroyEntity(marineShotZombieAction.zombieEntity); EntityManager.RemoveComponent <HasTarget>(marineShotZombieAction.marineEntity); } else { // Zombie still has health EntityManager.SetComponentData(marineShotZombieAction.zombieEntity, zombieHealth); } } else { if (EntityManager.Exists(marineShotZombieAction.marineEntity) && !EntityManager.Exists(marineShotZombieAction.zombieEntity)) { // Marine exists but zombie is dead EntityManager.RemoveComponent <HasTarget>(marineShotZombieAction.marineEntity); } } } }
private void PlayerAimWeapon_OnShoot(object sender, PlayerAimWeapon.OnShootEventArgs e) { //UtilsClass.ShakeCamera(.6f, .05f); WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition); //Shoot_Flash.AddFlash(e.gunEndPointPosition); World_Sprite world_Sprite = World_Sprite.Create(e.gunEndPointPosition, GameAssets.i.s_ShootFlash); FunctionTimer.Create(world_Sprite.DestroySelf, .1f); Vector3 shootDir = (e.shootPosition - e.gunEndPointPosition).normalized; shootDir = UtilsClass.ApplyRotationToVector(shootDir, 90f); //ShellParticleSystemHandler.Instance.SpawnShell(e.shellPosition, shootDir); }
private void EnemyAim_OnShoot(object sender, CharacterAim_Base.OnShootEventArgs e) { Shoot_Flash.AddFlash(e.gunEndPointPosition); WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition); UtilsClass.ShakeCamera(.3f, .05f); SpawnBulletShellCasing(e.gunEndPointPosition, e.shootPosition); // Player hit? if (e.hitObject != null) { Player player = e.hitObject.GetComponent <Player>(); if (player != null) { player.Damage(this, EnemyMain.EnemyStats.damageMultiplier); } } }
private void PlayerSwapAimNormal_OnShoot(object sender, CharacterAim_Base.OnShootEventArgs e) { Shoot_Flash.AddFlash(e.gunEndPointPosition); WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition); UtilsClass.ShakeCamera(.6f, .05f); SpawnBulletShellCasing(e.gunEndPointPosition, e.shootPosition); if (weapon.GetWeaponType() == Weapon.WeaponType.Shotgun) { // Shotgun spread int shotgunShells = 4; for (int i = 0; i < shotgunShells; i++) { WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition + UtilsClass.GetRandomDir() * UnityEngine.Random.Range(-20f, 20f)); if (i % 2 == 0) { SpawnBulletShellCasing(e.gunEndPointPosition, e.shootPosition); } } } switch (weapon.GetWeaponType()) { default: case Weapon.WeaponType.Pistol: Sound_Manager.PlaySound(Sound_Manager.Sound.Pistol_Fire, GetPosition()); break; case Weapon.WeaponType.Rifle: Sound_Manager.PlaySound(Sound_Manager.Sound.Rifle_Fire, GetPosition()); break; case Weapon.WeaponType.Shotgun: Sound_Manager.PlaySound(Sound_Manager.Sound.Shotgun_Fire, GetPosition()); break; } // Any enemy hit? if (e.hitObject != null) { Enemy enemy = e.hitObject.GetComponent <Enemy>(); if (enemy != null) { enemy.Damage(this, weapon.GetDamageMultiplier()); } ShieldFieldTransformer shieldFieldTransformer = e.hitObject.GetComponent <ShieldFieldTransformer>(); if (shieldFieldTransformer != null) { shieldFieldTransformer.Damage(this, weapon.GetDamageMultiplier()); } } }
private void CharacterAimHandler_OnShoot(object sender, CharacterAimHandler.OnShootEventArgs e) { Shoot_Flash.AddFlash(e.gunEndPointPosition); WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition); UtilsClass.ShakeCamera(.6f, .05f); // Any enemy hit? RaycastHit2D raycastHit = Physics2D.Raycast(e.gunEndPointPosition, (e.shootPosition - e.gunEndPointPosition).normalized, Vector3.Distance(e.gunEndPointPosition, e.shootPosition)); if (raycastHit.collider != null) { EnemyHandler enemyHandler = raycastHit.collider.gameObject.GetComponent <EnemyHandler>(); if (enemyHandler != null) { enemyHandler.Damage(characterAimHandler); } } }
private void CharacterBase_OnShoot(object sender, CharacterAim_Base.OnShootEventArgs e) { Shoot_Flash.AddFlash(e.gunEndPointPosition); WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition); ShakeCamera(.3f, .05f); // Any hit? Player? RaycastHit2D raycastHit = Physics2D.Raycast(e.gunEndPointPosition, (e.shootPosition - e.gunEndPointPosition).normalized, Vector3.Distance(e.gunEndPointPosition, e.shootPosition)); if (raycastHit.collider != null) { PlayerAim player = raycastHit.collider.gameObject.GetComponent <PlayerAim>(); if (player != null) { player.Damage(this); } } }
private void ShootUnit(UnitGridCombat unitGridCombat, Action onShootComplete) { GetComponent <IMoveVelocity>().Disable(); Vector3 attackDir = (unitGridCombat.GetPosition() - transform.position).normalized; //UtilsClass.ShakeCamera(.6f, .1f); GameHandler_GridCombatSystem.Instance.ScreenShake(); characterBase.PlayShootAnimation(attackDir, (Vector3 vec) => { Shoot_Flash.AddFlash(vec); WeaponTracer.Create(vec, unitGridCombat.GetPosition() + GetRandomDir() * UnityEngine.Random.Range(-2f, 4f)); unitGridCombat.Damage(this, UnityEngine.Random.Range(4, 12)); }, () => { characterBase.PlayIdleAnim(); GetComponent <IMoveVelocity>().Enable(); onShootComplete(); }); }
private void Update() { switch (state) { case State.Normal: if (enemyRTS != null) { float attackRange = 70f; if (Vector3.Distance(transform.position, enemyRTS.GetPosition()) < attackRange) { MoveTo(transform.position); GetComponent <IMoveVelocity>().Disable(); Vector3 attackDir = (enemyRTS.GetPosition() - transform.position).normalized; UtilsClass.ShakeCamera(.6f, .1f); characterBase.PlayShootAnimation(attackDir, (Vector3 vec) => { Shoot_Flash.AddFlash(vec); WeaponTracer.Create(vec, enemyRTS.GetPosition()); enemyRTS.Damage(this, Random.Range(5, 15)); }, () => { characterBase.PlayIdleAnim(); GetComponent <IMoveVelocity>().Enable(); state = State.Normal; }); state = State.Attacking; } else { // Move Closer MoveTo(enemyRTS.GetPosition()); } } else { // No enemy } break; case State.Attacking: break; } }