private void Fire() { if (_canAttack) { _SOEffectHandler.PlayEffect(EffectEnums.SniperBullet, _endOfBarrel.transform.position); _audioSource.pitch = Random.Range(0.75f, 1.5f); _audioSource.Play(); _animationManager.Play(3); _canAttack = false; } }
private void OnCollisionEnter2D(Collision2D otherGO) { string tag = otherGO.gameObject.tag; if (tag == "Player") { otherGO.gameObject.GetComponent <PlayerHealth>().DecrementPlayerHealth(_damage); Vector2 direction = otherGO.gameObject.GetComponent <BoxCollider2D>().bounds.center - transform.position; //otherGO.gameObject.GetComponent<Rigidbody2D>().AddForce(direction.normalized * _knockBack, ForceMode2D.Impulse); otherGO.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(direction.normalized.x * _knockBack, direction.normalized.y * _knockBack); } _SOEffectHandler.PlayEffect(EffectEnums.SniperBulletImpact, transform.position); Destroy(gameObject); }
// User Raycasting on each lightning bolt to determine if a collision has occured. private void CheckCollisions() { for (int i = 0; i < _lightning.Length; ++i) { RaycastHit2D hit = Physics2D.Raycast((Vector2)_endOfBarrel.transform.position, _directions[i], _magnitudes[i], _whatToHit); if (hit.collider != null) { string hitTagName = hit.collider.gameObject.tag; if (hitTagName == "Enemy") { hit.collider.gameObject.GetComponentInParent <EnemyBasicBehaviors>().DecrementHealth(_damageAmount); } else { _magnitudes[i] = Vector3.Magnitude(hit.point - (Vector2)_endOfBarrel.transform.position); } if (hitTagName == "SwarmerPodBattery") { hit.collider.gameObject.GetComponentInParent <SwarmPodSpawner>().DestroyPod(); } else if (hitTagName == "AcidBall") { hit.collider.gameObject.GetComponent <AcidBallBehavior>().Splatter(); } else if (hitTagName == "SniperBullet") { hit.collider.gameObject.GetComponent <SniperDealDamage>().Destroy(); } _SOEffectHandler.PlayEffect(EffectEnums.LightningImpact, hit.point); } } }
private void OnCollisionEnter2D(Collision2D otherGO) { if (otherGO.gameObject.tag == "Enemy") { otherGO.gameObject.GetComponentInParent <EnemyBasicBehaviors>().DecrementHealth(_damageAmount); } if (otherGO.collider.gameObject.tag == "SwarmerPodBattery") { otherGO.gameObject.GetComponentInParent <SwarmPodSpawner>().DestroyPod(); } if (otherGO.gameObject.tag != "Player" && otherGO != null) { _SOEffectHandler.PlayEffect(EffectEnums.CrystalImpact, transform.position, gameObject.transform.localEulerAngles.z); Destroy(gameObject); } }
private void OnEnable() { _effectPositions = GetComponentsInChildren <Transform>(); // Start the battery indication effect animation _podBatteryIndicatorGO = _SOEffectHandler.PlayEffect(EffectEnums.PodBatteryIndicator, _effectPositions[1].position); _podBatteryIndicatorGO1 = _SOEffectHandler.PlayEffect(EffectEnums.PodBatteryIndicator, _effectPositions[6].position); _swarm = new GameObject[sizeOfSwarm]; _timer = Time.time; }
private void OnEnable() { if (enemyType == EnemyType.AcidSwarmer) { _timer = Time.time; _effectDelay = Random.Range(1.0f, 3.0f); } else if (enemyType == EnemyType.ExplodingSwamer) { _effect = _SOEffectHandler.PlayEffect(EffectEnums.SwarmerExplosiveEffect, transform.position); } else if (enemyType == EnemyType.Flying) { _effect = _SOEffectHandler.PlayEffect(EffectEnums.Flying_Swarmer_Exhaust, transform.position); } else if (enemyType == EnemyType.Charger) { _effect = _SOEffectHandler.PlayEffect(EffectEnums.ChargerExhaust, transform.position); } _effectPositions = GetComponentsInChildren <Transform>(); }
private void DeployBodyParts() { GameObject effectInstance = _SOEffectHandler.PlayEffect(EffectEnums.SwarmerDeathExplosion, transform.position); _audio.clip = _audioClips[Random.Range(0, 2)]; _audio.pitch = Random.Range(0.75f, 1.5f); _audio.Play(); effectInstance.transform.localScale = new Vector3(0.85f, 0.85f, 1.0f); effectInstance.GetComponent <AudioSource>().pitch = Random.Range(0.75f, 1.5f); for (int i = 0; i < _enemyBodyParts.bodyParts.Length; ++i) { GameObject instance = Instantiate(_enemyBodyParts.bodyParts[i], transform.position, Quaternion.identity) as GameObject; _bodyParts.Add(instance); instance.GetComponent <EnableCollider>().mainMenu = true; instance.GetComponent <Rigidbody2D>().gravityScale = 2.0f; instance.transform.localScale = new Vector3(0.2f, 0.2f, 1.0f); instance.GetComponent <Rigidbody2D>().AddForce(new Vector2(Random.Range(-10.0f, -5.0f), Random.Range(4.0f, 15.0f)), ForceMode2D.Impulse); instance.GetComponent <Rigidbody2D>().AddTorque(Random.Range(-500.0f, 500.0f)); } }
private GameObject SpawnPlayer() { GameObject _player = Instantiate(Resources.Load("MainCharacter/MainCharacter", typeof(GameObject)) as GameObject, transform.position, Quaternion.identity) as GameObject; SOEffectHandler.PlayEffect(EffectEnums.PlayerRespawn, SOSaveHandler.CheckpointPosition); _player.transform.position = SOSaveHandler.CheckpointPosition; _IM.AssignPlayer(_player); if (SOSaveHandler.CurrentLevel > 1) { _player.GetComponentInChildren <WeaponSelect>().SGAvailable = true; } else if (SOSaveHandler.CurrentLevel == 1 && SOSaveHandler.CheckpointID >= 7 && SOSaveHandler.CheckpointID != 8) { _player.GetComponentInChildren <WeaponSelect>().SGAvailable = true; } else { _player.GetComponentInChildren <WeaponSelect>().SGAvailable = false; } return(_player); }
public void Splatter() { _SOEffectHandler.PlayEffect(EffectEnums.AcidBallSplatter, transform.position, 50.0f); Destroy(gameObject); }
private void OnEnable() { _laserEffect = _SOEffectHandler.PlayEffect(EffectEnums.SniperLaserEffect, _endOfBarrel.position); }
private void Update() { if (_entity == null) { _entity = GetComponent <SpriterDotNetUnity.SpriterDotNetBehaviour>().ChildData; } // if the player dies, stop any velocity the player had, place them at the last checkpoint, and reset their health to 100%. if (_health <= 0) { if (!_deathAnimationPlayed) { if (_inputManager == null) { _inputManager = InputManager.Instance.GetComponent <InputManager>(); } _inputManager.StopInput(); GetComponent <BoxCollider2D>().enabled = false; GetComponent <PolygonCollider2D>().enabled = false; _playerBody.SetActive(false); if (!_collisionState.OnSolidGround) { _SOEffectHandler.PlayEffect(EffectEnums.Player_Death00, transform.position); } else { _SOEffectHandler.PlayEffect(EffectEnums.Player_Death01, transform.position); } _deathAnimationPlayed = true; DeployBodyParts(); _timer = Time.time; if (OnPlayerDeath != null) { OnPlayerDeath(); } // This tells the save file to add to the number of deaths. } GetComponent <Rigidbody2D>().velocity = new Vector3(0.0f, 0.0f, 0.0f); GetComponent <Rigidbody2D>().gravityScale = 0.0f; GetComponent <PlayerMovementManager>().ClearQueue(); StartCoroutine(ReloadLevelDelay()); //if (Time.time - _timer > 1.0f) { // transform.position = _GM.SOSaveHandler.CheckpointPosition; // GetComponent<PlayerMovementManager>().ClearQueue(); // if (Camera.main.WorldToViewportPoint(_GM.SOSaveHandler.CheckpointPosition).x > 0.1f && // Camera.main.WorldToViewportPoint(_GM.SOSaveHandler.CheckpointPosition).x < 0.9f) { // // Delay the player from any input for 1.5 seconds to ensure they do not immediate fly to their death // // Call the respawn effect and restore all the default values for the player. // _inputManager.PauseInput(1.25f); // GetComponent<Rigidbody2D>().gravityScale = 40.0f; // _SOEffectHandler.PlayEffect(EffectEnums.PlayerRespawn, _GM.SOSaveHandler.CheckpointPosition); // _SOWeaponManager.Reload(); // _health = _maxHealth; // _playerBody.SetActive(true); // UpdateHealth(_health); // _deathAnimationPlayed = false; // } //} } if (_killPlayerCalled) { KillPlayer(); } if (_effect != null) { // If an effect is playing and then the player dies, stop the effect at once. if (_health < 0) { _duration = 0.0f; _SOEffectHandler.StopEffect(_effect); foreach (GameObject sprite in _entity.Sprites) { //Color spriteColor = sprite.GetComponent<SpriteRenderer>().color; sprite.GetComponent <SpriteRenderer>().color = Color.white; } } // if there is any type of effect associated with the player, ensure it is following them with a slight offset. _effect.transform.position = transform.position + new Vector3(0.0f, 25.0f, 0.0f); } // If an enemy has damaged the player and their is an effect to be played, // keep calling the damage and effect to do damage over time. if (_duration != 0.0f) { if (Time.time - _timer < _duration) { if (_damageType == DamageEnum.Acid && _canTakeDamage) { _scrnShkRequest.ShakeRequest(); StartCoroutine(RecoveryDelay()); } ReturnToNormalColor(); } else { _duration = 0.0f; _SOEffectHandler.StopEffect(_effect); } } }
private void FixedUpdate() { // Get the position of the player's collider box every fixed update _rayOrigin[0] = new Vector2(_box.bounds.min.x + _rayCastOffset.x, _box.bounds.min.y + 1.0f); _rayOrigin[1] = new Vector2(_box.bounds.max.x - _rayCastOffset.x, _box.bounds.min.y + 1.0f); //// Get the position of the player's collider box every fixed update //if ((_controller.GetButtonPress(Buttons.AimRight) || _controller.GetButtonPress(Buttons.AimLeft))) { // _rayOrigin[0] = new Vector2(_box.bounds.center.x * -(float)_controller.FacingDirection, _box.bounds.min.y + 1.0f); // _rayOrigin[1] = new Vector2(_box.bounds.center.x + 13.5f * -(float)_controller.FacingDirection, _box.bounds.min.y + 1.0f); //} //else { // _rayOrigin[0] = new Vector2(_box.bounds.center.x + 5.0f * (float)_controller.FacingDirection, _box.bounds.min.y + 1.0f); // _rayOrigin[1] = new Vector2(_box.bounds.center.x - 7.75f * (float)_controller.FacingDirection, _box.bounds.min.y + 1.0f); //} // For both sides of the player, check if the Raycast is touching the floor. // Only check the right side if the player's left side is not touching. Most of the time, // the player will be traveling left to right. Therefore, we should be checking the left side more. RaycastHit2D hit; for (int i = 0; i < 2; ++i) { hit = Physics2D.Raycast(_rayOrigin[i], _direction, _distance, _whatToHit); if (hit.collider != null) { Debug.DrawRay(_rayOrigin[i], new Vector3(0.0f, -1.0f * _distance, 0.0f), Color.white); _touchedGround = _body2d.velocity.y <= 2.0f ? true : false; break; } } // Send out this event if the player wasn't on the ground and its status has changed. if (!_onSolidGround && _touchedGround) { if (SceneManager.GetActiveScene().name == "Main Menu") { GameObject instance = _SOEffectHandler.PlayEffect(EffectEnums.LandingDust, new Vector2(transform.position.x, transform.position.y - 1.0f)); instance.transform.localScale = new Vector3(0.75f, 0.75f, 1.0f); } else { _SOEffectHandler.PlayEffect(EffectEnums.LandingDust, transform.position); } if (OnHitGround != null) { OnHitGround(); } } // Send out this event if the player was on the ground and its status has changed. else if (_onSolidGround && !_touchedGround) { if (OnLifted != null) { OnLifted(); } } _onSolidGround = _touchedGround ? true : false; // Update the collision state. _touchedGround = false; // Reset the collision check. }