private void OnCollisionEnter2D(Collision2D collision) { GameObject hitObject = collision.gameObject; EnemyDeath enemy = hitObject.GetComponent <EnemyDeath>(); if (hitObject == GameObject.Find("Player")) { PlayerCharacter p = hitObject.GetComponent <PlayerCharacter>(); p.Hurt(); Destroy(this.gameObject); } else if (enemy != null) { EnemyDeath e = hitObject.GetComponent <EnemyDeath>(); e.Die(); Destroy(this.gameObject); } else { var speed = lastVelocity.magnitude; //We can reduce this if we want var direction = Vector3.Reflect(lastVelocity.normalized, collision.contacts[0].normal); rb.velocity = direction * speed; } }
void Shoot() { //railgunShoot.Play(); FindObjectOfType <AudioManager>().PlaySound("PlayerShoot"); gunKickBackAnim.Play("GunKickBack", -1, 0f); bulletCharge.Play(); gunCircle.Play(); bulletFlash.Play(); gunBurstAmmo.Play(); // bulletTrail.Play(); hasBullet = false; RaycastHit hit; if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range)) { //VFX GameObject impactVFX = Instantiate(gunImpactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactVFX, 1); //Shooting Enemy EnemyDeath enemy = hit.transform.GetComponent <EnemyDeath>(); if (enemy != null) { enemy.Die(); hasBullet = true; FindObjectOfType <AudioManager>().PlaySound("Reload"); CameraShaker.Instance.ShakeOnce(magnitude, roughness, fadeInTime, fadeOutTime); } //Reverse Gravity if (hit.collider.CompareTag("ReverseGravity")) { ReverseGravity(); hasBullet = true; } TrailSpawn(hit.point); } else { TrailSpawn(trailMissEnd.transform.position); //Not hitting anything } }
public void RestoreSaveData(object dataIn) { if (!enemy) { return; } EnemyData_v1 data = (EnemyData_v1)dataIn; if (data.loadID != LoadID) { return; } DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>(); EnemySenses senses = enemy.GetComponent <EnemySenses>(); EnemyMotor motor = enemy.GetComponent <EnemyMotor>(); EnemyEntity entity = entityBehaviour.Entity as EnemyEntity; // Restore enemy career or class if different if (entity.EntityType != data.entityType || entity.CareerIndex != data.careerIndex) { SetupDemoEnemy setupEnemy = enemy.GetComponent <SetupDemoEnemy>(); setupEnemy.ApplyEnemySettings(data.entityType, data.careerIndex, data.isHostile); setupEnemy.AlignToGround(); } // Restore enemy position enemy.transform.position = data.currentPosition; enemy.transform.rotation = data.currentRotation; entity.MaxHealth = data.startingHealth; entity.CurrentHealth = data.currentHealth; entity.CurrentFatigue = data.currentFatigue; entity.CurrentMagicka = data.currentMagicka; motor.IsHostile = data.isHostile; senses.HasEncounteredPlayer = true; // Set monster as dead if (data.isDead) { EnemyDeath enemyDeath = enemy.GetComponent <EnemyDeath>(); if (enemyDeath) { enemyDeath.Die(false); } } }
private void OnTriggerEnter(Collider other) { EnemyDeath enemy = other.GetComponent<EnemyDeath>(); if(enemy != null) { enemy.Die(); CameraShaker.Instance.ShakeOnce(magnitude, roughness, fadeInTime, fadeOutTime); s.hasBullet = true; FindObjectOfType<AudioManager>().PlaySound("Reload"); } if (other.CompareTag("ReverseGravity")) { s.ReverseGravity(); s.hasBullet = true; FindObjectOfType<AudioManager>().PlaySound("Reload"); } }
private void OnCollisionEnter2D(Collision2D collision) { GameObject hitObject = collision.gameObject; EnemyDeath enemy = hitObject.GetComponent <EnemyDeath>(); ShieldPowerUp shield = hitObject.GetComponent <ShieldPowerUp>(); if (hitObject == GameObject.Find("Player")) { PlayerCharacter p = hitObject.GetComponent <PlayerCharacter>(); p.Hurt(); Destroy(this.gameObject); } else if (enemy != null) { EnemyDeath e = hitObject.GetComponent <EnemyDeath>(); e.Die(); Destroy(this.gameObject); FindObjectOfType <PlayerCharacter>().StreakIncrease(); } else if (shield != null && firstWall == false) { Destroy(this.gameObject); } else if (shield != null && firstWall == true) { } else { var speed = lastVelocity.magnitude; //We can reduce this if we want var direction = Vector3.Reflect(lastVelocity.normalized, collision.contacts[0].normal); rb.velocity = (direction * speed) * 0.95f; if (firstWall == true) { FindObjectOfType <PlayerCharacter>().StreakReset(); firstWall = false; } } }