void OnEnable() { if (dmgPlayer == null) { dmgPlayer = GetComponent <DamagePlayerDefaults>(); } // If ignoring first ground collision, check if projectile spawns inside ground if (ignoreFirstGround) { // Is collider overlapping with a ground layer on spawn? coll.OverlapCollider(contactFilter, firstGroundResults); if (firstGroundResults[0] != null) { hasExited = false; // If inside ground, ignore this collision } else { hasExited = true; // If not inside ground, treat collisions normally and do not ignore any } } // Reset speed on enable dmgPlayer.Speed = dmgPlayer.DmgPlayer.baseSpeed; }
// Reduce DamagePlayer speed void OnTriggerEnter2D(Collider2D other) { // Slow damage player objects such as projectiles if (other.tag == "DamagePlayer") { DamagePlayerDefaults dmgPlayer = other.GetComponent <DamagePlayerDefaults>(); if (dmgPlayer != null) { dmgPlayer.RestoreMoveSpeedTime = Time.time + restoreProjectileSpeedDelay; dmgPlayer.Speed = dmgPlayer.DmgPlayer.baseSpeed * projectileSlowMultiplier; } } // Slow enemies if (other.tag == "Enemy") { EnemyDefaults enemy = other.GetComponent <EnemyDefaults>(); if (enemy != null) { enemy.RestoreMoveSpeedTime = Time.time + restoreEnemySpeedDelay; // Apply slow while also taking into consideration the move speed multiplier of enemy enemy.MoveSpeed = (enemy.Enemy.baseMoveSpeed * ((enemy.MoveSpeedMultiplier - 1) + enemySlowMultiplier)); } } }
void Start() { dmgPlayer = GetComponent <DamagePlayerDefaults>(); // Set starting position and move from there nextPos = startPos; transform.position = pos[nextPos].position; }
void OnEnable() { if (dmgPlayer == null) { dmgPlayer = GetComponent <DamagePlayerDefaults>(); } // Reset speed on enable dmgPlayer.Speed = dmgPlayer.DmgPlayer.baseSpeed; }
void Awake() { if (disabledEffectPrefab != null) { disabledEffect = Instantiate(disabledEffectPrefab, Vector3.down * 50, Quaternion.identity); disabledEffect.SetActive(false); } dmgDefaults = GetComponent <DamagePlayerDefaults>(); }
void Awake() { player = GameObject.FindGameObjectWithTag("Player"); origScale = transform.localScale; dmgPlayer = GetComponent <DamagePlayerDefaults>(); if (disabledEffectPrefab != null) { disabledEffect = Instantiate(disabledEffectPrefab, transform.position, Quaternion.identity); disabledEffect.SetActive(false); } }
void Awake() { origScale = transform.localScale; cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraControl>(); rb = GetComponent <Rigidbody2D>(); dmgPlayer = GetComponent <DamagePlayerDefaults>(); if (disabledEffectPrefab != null) { disabledEffect = Instantiate(disabledEffectPrefab, transform.position, Quaternion.identity); disabledEffect.SetActive(false); } ignoreGround = dmgPlayer.DmgPlayer.ignoreGround; ignoreFirstGround = dmgPlayer.DmgPlayer.ignoreFirstGround; coll = GetComponent <Collider2D>(); ground = LayerMask.NameToLayer("Ground"); contactFilter.SetLayerMask(LayerMask.GetMask("Ground")); // Set contact filter to only look for ground layers }
//If collides with anything that damages player, take damage void OnTriggerEnter2D(Collider2D other) { EnemyDefaults enemyDmg = other.GetComponent <EnemyDefaults>(); DamagePlayerDefaults dmgPlayer = other.GetComponent <DamagePlayerDefaults>(); bool isEnemy = enemyDmg != null ? true : false; if ((enemyDmg != null || dmgPlayer != null) && Time.time > damagedTime && !dead) { int dmg = isEnemy ? enemyDmg.Dmg : dmgPlayer.Dmg; // If dmg is 0 or less, do nothing and return if (dmg <= 0) { return; } // Disable other object if DamagePlayer property is true if (dmgPlayer != null && dmgPlayer.DmgPlayer.disableOnPlayer) { other.gameObject.SetActive(false); } DisplayDmgNum(dmg); //Show damage number currentHP -= dmg; //Calculate HP if (currentHP < 0) //Do not go below 0 hp { currentHP = 0; } OnHealthChange.Invoke(); // OnHealthChanged event damagedTime = Time.time + damagedDelay; //Take damage rate //Damaged response PlaySound(); StartCoroutine(Knockback(other.gameObject)); StartCoroutine(FlashRed()); } }
void Start() { dmgPlayerDefaults = GetComponent <DamagePlayerDefaults>(); nextPos = posB; }