void OnTriggerEnter2D(Collider2D otherCollider) { // Is this a shot? ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null) { // Avoid friendly fire if (shot.isEnemyShot != isEnemy) { Damage(shot.damage); // Destroy the shot Destroy(shot.gameObject); } } DamageScript damage1 = otherCollider.gameObject.GetComponent <DamageScript>(); if (damage1 != null) { if (damage1.isEnemyShot != isEnemy) { Damage(damage1.damage); } } }
private void CheckDamage(GameObject other) { // Deals damage if it is one of the damageTags if (lastDamaged >= damageCooldown && damageTags.Contains(other.tag)) { DamageScript dmgScript = other.GetComponent <DamageScript>(); if (dmgScript != null) { // Take Damage Debug.Log("hit"); InflictDamage(dmgScript.damage); lastDamaged = 0.0f; // Trigger damaged animation if (anim != null) { anim.SetTrigger(damageHash); } } else { Debug.LogWarning(gameObject.name + " should take damage, but the damaging object, " + other.name + " has no DamageScript attached to it."); } } }
private bool playerFound = false; //tell if player is in range or not // Use this for initialization protected virtual void Start() { damageScript = GetComponent <DamageScript>(); //get the component scaleX = transform.localScale.x; //set the varible value currentTime = 0; //set current time to zero playerTarget = GameObject.FindGameObjectWithTag("Player").transform; //get player reference }
// Use this for initialization void Start() { gunCoolDown = 0; //at start we want it to zero so player can immideatly fire currentImmuneTime = 0; //at start we want it to zero so player can get hurt currentlayerChangeTime = layerChangeTime; myBody = GetComponent <Rigidbody2D>(); //get the component anim = GetComponent <Animator>(); //get the component damageScript = GetComponent <DamageScript>(); //get the component GameManager.instance.playerDead = false; //set dead to false GameManager.instance.levelComplete = false; //set level complete to false speed = 3 + 0.5f * GameManager.instance.speed; //set the speed if (speed > 8) { speed = 8; //if speed is more than 8 we set it to 8 } gunFireRate = 1f - 0.2f * GameManager.instance.gunFireRate; //set gunFireRate if (gunFireRate < 0.2f) { gunFireRate = 0.2f; //if gunFireRate is less than 0.2f , we set it to 0.2f } gunDamage = GameManager.instance.gunDamage; //set gun damage #if MOBILE_INPUT usingKeyboard = false; #else usingKeyboard = true; #endif }
/* * Using the DamageScript class, when the enemy laser hits the player, its health will be reduced accordingly. When the * players health reaches zero, the player game object is destroyed. If a gameobject collides with our player ship, * that object will also be destroyed, like the laser. * * Null reference error here?? */ private void OnTriggerEnter2D(Collider2D collision) { DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>(); if (local_damageScript == false) { return; } field_int_playerHealth -= local_damageScript.GetFieldIntDamage(); field_dob_percentage = (field_int_playerHealth) / (field_dob_playerHealthCopy) * 100; //Debug.Log(field_dob_percentage); local_damageScript.Destroy(); triggerHitSound(); if (field_int_playerHealth <= 0) { FindObjectOfType <LevelLoadingScript>().LoadGameOverScreen(); Destroy(gameObject); triggerDeathAnimation(); triggerDeathSound(); } }
private Transform playerTarget; //ref to target // Use this for initialization void Start() { playerTarget = GameObject.FindGameObjectWithTag("Player").transform; //get reference to the player currentAttackTime = attackTime; //set the attack time currentIdleTime = idleTime; //set the idle time damageScript = GetComponent <DamageScript>(); //get component anim = GetComponent <Animator>(); //get component }
public void DoDamage(Collider c) { if (c.gameObject.tag == "Enemy") { DamageScript ds = c.gameObject.GetComponent <DamageScript>(); ds.AddDamage(damage); } }
// Use this for initialization public new virtual void Start() { base.Start(); anim = GetComponentInChildren <Animator> (); rBody = GetComponent <Rigidbody>(); player = GameObject.FindGameObjectWithTag("Player"); _DamageScript = player.GetComponent <DamageScript>(); stunSpawnOnce = true; }
private void Start() { _attackCooldown = 0f; // init needed scripts _player = GameObject.Find("PlayerHans"); _projectileScript = projectilePrefab.GetComponent <ProjectileScript>(); _damageScript = projectilePrefab.GetComponent <DamageScript>(); _audioData = GetComponent <AudioSource>(); }
public override void damageProc(DamageScript scr) { if (scr == null) return; hp -= scr.getDamage(); if(hp < 1) { GameManager.gameOver(); } }
public void ShootRay() { if (Physics.Raycast(transform.position, transform.forward, out hit, 1000, layerMask)) { DamageScript damageScript = hit.collider.gameObject.GetComponent <DamageScript>(); if (damageScript != null) { //damageScript.HealthPoints -= 25; } } }
void Start() { if (cam == null) { Debug.LogError("PlayerShoot: No camera referenced!"); this.enabled = false; } inventory = GetComponentInChildren <Inventory>(); _damageScript = GetComponent <DamageScript>(); }
public override void damageProc(DamageScript scr) { if (scr == null) { return; } hp -= scr.getDamage(); if (hp < 1) { GameManager.gameOver(); } }
private float x = 0; //this is to increase the beam size with time // Use this for initialization void Start() { anim = GetComponent <Animator>(); //get the component damageScript = GetComponent <DamageScript>(); //get the component scaleX = transform.localScale.x; //set the scale currentIdleTime = idleTime; //set idle time currentAttackTime = attackTime; //set attack time alienMode = AlienMode.idle; //set mode movingRight = false; //moving right is false at start target = leftEnd.position; //at start target is left end currentCoolDown = 0; //cool down time is zero }
private void OnTriggerEnter2D(Collider2D collision) { DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>(); field_float_health -= local_damageScript.GetFieldIntDamage(); local_damageScript.Destroy(); if (field_float_health <= 0) { Destroy(gameObject); triggerDeathAnimation(); triggerDeathSound(); } }
void ShootGun() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { DamageScript target = hit.transform.GetComponent <DamageScript>(); if (target != null) { target.TakeDamage(damage); } } }
private void OnCollisionEnter(Collision collision) { DamageScript ds = collision.gameObject.GetComponent <DamageScript>(); if (ds) { Health -= ds.Damage; if (Health <= 0) { Debug.Log("Killing off " + name); GetComponent <OnDeathScript>().PerformDeathActionAndDestroy(); } } }
private bool playerInRange = false; //check if player is in range or not // Use this for initialization void Start() { gunCoolDown = 0; //set it to zero playerTarget = GameObject.FindGameObjectWithTag("Player"); //get the player anim = GetComponent <Animator>(); //get the component damageScript = GetComponent <DamageScript>(); //get the component scaleX = transform.localScale.x; //set the scale x value if (movingRight) { target = rightEnd.position; //depending on direction set the target } else if (!movingRight) { target = leftEnd.position; } }
void Slash() { attackObject = Instantiate(dmgObject, transform); attackvars = attackObject.GetComponent <DamageScript>(); if (facingRight) { kbForce = 8f; lungeDir = 1; } else { kbForce = -8f; lungeDir = -1; } attackvars.Setup(damage, kbForce, "Evil", new Vector2(1.75f, 0.9f), new Vector2(0.5f, 0f), 4, 45f * lungeDir); rg2d.AddForce(new Vector2(10f * lungeDir, 0f), ForceMode2D.Impulse); }
public override void Start() { _playerInfo = GameObject.FindGameObjectWithTag("Info").GetComponent <PlayerInfo>(); base.Start(); gameObject.transform.eulerAngles = ResetEuler; _damageScript = GetComponentInChildren <DamageScript>(); hitPoints = _playerInfo.life; rBody = GetComponent <Rigidbody>(); anim = GetComponentInChildren <Animator>(); _cameraScript = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraScript>(); //Verifica se o loading terminou if (loaded == true) { anim.SetBool("loaded", true); Cinematic = true; rBody.velocity = new Vector3(10, 5, 0); } }
public override void damageProc(DamageScript scr) { if (scr == null) return; hp -= scr.getDamage(); if(hp < 1 & !death) { death = true; if (gameObject.GetComponent<KaboonScript>() != null) { gameObject.GetComponent<KaboonScript>().setKaboon(); } //爆発アニメーション explosion(); //スコアに追加 GameManager.Score += score; } }
void Start() { GetComponent <BoxCollider>().isTrigger = true; _EV = GameDataContainer.Instance.GDC.EnemyValues.Find(o => o.Name == UnitName); if (_EV != null) { _DS = new DamageScript(_EV.Health, OnDeath); Debug.Log(_EV.Personality); if (_EV.Personality) { PickPersonality(); } } else { Debug.LogWarning("NO DATA FOUND"); Destroy(this.gameObject); } }
public void ReleaseFireBall() { BaseSkillInfo.OnCoolDown = false; if (gameObject.CompareTag("Enemy")) { BaseSkillInfo.SkillObjects[0].transform.LookAt(BaseSkillInfo.TargetEnemy.transform.position); } BaseSkillInfo.SkillObjects[0].GetComponent <Rigidbody>().AddForce(BaseSkillInfo.SkillObjects[0].transform.forward * 500); DamageScript DmgScript = BaseSkillInfo.SkillObjects[0].AddComponent <DamageScript>(); DmgScript.TargetTag = BaseSkillInfo.TargetTag; DmgScript.Attack = BaseSkillInfo.PlayerStats.ATK; DmgScript.DamageType = BaseSkillInfo.DamageType; Destroy(BaseSkillInfo.SkillObjects[0], 10.0f); }
public override void damageProc(DamageScript scr) { if (scr == null) { return; } hp -= scr.getDamage(); if (hp < 1 & !death) { death = true; if (gameObject.GetComponent <KaboonScript>() != null) { gameObject.GetComponent <KaboonScript>().setKaboon(); } //爆発アニメーション explosion(); //スコアに追加 GameManager.Score += score; } }
private void FixedUpdate() { if (rg2d.velocity.x > 0f && !facingRight) { Flip(); } else if (rg2d.velocity.x < 0f && facingRight) { Flip(); } hitCheck = Physics2D.OverlapCircle(hitboxOrigin.position, 0.1f, whatHitsThis); if (hitCheck && !hasHit) { anim.SetBool("hit", true); hasHit = true; attackObj = Instantiate(dmgObject, transform); attackvars = attackObj.GetComponent <DamageScript>(); attackvars.Setup(damage, knockback * Mathf.Sign(rg2d.velocity.x), "Evil", new Vector2(.02f, .02f), new Vector2(0.1f, 0.01f), 1, 10f * Mathf.Sign(rg2d.velocity.x)); trailParticles.Stop(); hitParticles = Instantiate(hitParticlesObj, transform).GetComponent <ParticleSystem>(); hitParticles.transform.position = transform.position; } }
void SlapLunge() { attackObj = Instantiate(damageObj, transform); attackvars = attackObj.GetComponent <DamageScript>(); rg2d.velocity = new Vector2(0f, 0f); if (facingRight) { //rg2d.AddForce(new Vector2(lungePower, 0)); if (!anim.GetBool("Combo")) { float kbAngle = 45f; attackvars.Setup(10f, 4f, "Good", new Vector2(1.3f, 0.6f), new Vector2(0.4f, -0.2f), 1, kbAngle); } else { float kbAngle = 45f; attackvars.Setup(10f, 16f, "Good", new Vector2(1.3f, 0.6f), new Vector2(0.4f, -0.2f), 1, kbAngle); } } if (!facingRight) { //rg2d.AddForce(new Vector2(-lungePower, 0)); if (!anim.GetBool("Combo")) { float kbAngle = -45f; attackvars.Setup(10f, -4f, "Good", new Vector2(1.3f, 0.6f), new Vector2(0.4f, -0.2f), 1, kbAngle); } else { float kbAngle = -45f; //Debug.Log(kbAngle); attackvars.Setup(10f, -16f, "Good", new Vector2(1.3f, 0.6f), new Vector2(0.4f, -0.2f), 1, kbAngle); } } attackObj.transform.SetParent(transform); }
private void OnTriggerEnter2D(Collider2D collision) { DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>(); field_float_health -= local_damageScript.GetFieldIntDamage(); local_damageScript.Destroy(); triggerHitSound(); if (gameObject.tag == "Endboss" && field_float_health <= 0) { FindObjectOfType <LevelLoadingScript>().LoadLevel2(); Destroy(gameObject); triggerDeathAnimation(); triggerDeathSound(); addScorePoints(); } if (field_float_health <= 0) { Destroy(gameObject); triggerDeathAnimation(); triggerDeathSound(); addScorePoints(); } }
/* * Methods called by animations. */ public void SpawnDamage() { DamageScript.SpawnDamage(damagePoint.position, damageRadius, 1, health); }
public abstract void damageProc(DamageScript scr);
private void Start() { _player = GameObject.Find("PlayerHans"); _damageScript = GetComponent <DamageScript>(); _moveZombieToPlayer = GetComponent <MoveCharacterToPlayer>(); }
// Use this for initialization void Start() { smokeParticle = transform.GetComponent <ParticleSystem>(); hpRef = transform.parent.GetComponentInChildren <DamageScript>(); hpRefMikko = transform.parent.GetComponentInChildren <DamageScriptMikko>(); }
public void Awake() { damageScript = this.GetComponent <DamageScript>(); }