Damage info
Inheritance: UnityEngine.MonoBehaviour
Exemplo n.º 1
0
    public TestCharacter(string name) {
      charObj = new GameObject();
      charObj.name = name;
      character = charObj.AddComponent<Character>();
      Assert.NotNull(character);
      health = charObj.GetComponent<CharacterHealth>();
      Assert.NotNull(health);
      health.Start();

      enterHitBox = charObj.CreateChild("entreAreas").AddComponent<HitBox>();
      enterHitBox.type = HitBoxType.EnterAreas;
      enterHitBox.gameObject.layer = 1;

      enterBox2D = enterHitBox.gameObject.AddComponent<BoxCollider2D>();
      enterBox2D.size = new Vector2(1, 1);
      enterHitBox.owner = health;
      enterHitBox.Start();

      dealHitBox = charObj.CreateChild("dealHitBox").AddComponent<HitBox>();
      Assert.NotNull(dealHitBox);

      dealHitBox.type = HitBoxType.DealDamage;
      dealHitBox.collideWith = (1 << 2); // | (1 << ?)
      dealHitBox.gameObject.layer = 2;
      damage = dealHitBox.gameObject.AddComponent<Damage>();
      damage.causer = health;
      damage.Start();
      dealHitBox.owner = health;

      dealBox2D = dealHitBox.gameObject.AddComponent<BoxCollider2D>();
      dealBox2D.size = new Vector2(1, 1);
      dealHitBox.Start();

      recieveHitBox = charObj.CreateChild("recieveHitBox").AddComponent<HitBox>();
      Assert.NotNull(recieveHitBox);

      recieveHitBox.type = HitBoxType.RecieveDamage;
      recieveHitBox.collideWith = (1 << 2);
      recieveHitBox.gameObject.layer = 2;
      recieveHitBox.owner = health;

      recieveBox2D = recieveHitBox.gameObject.AddComponent<BoxCollider2D>();
      recieveBox2D.size = new Vector2(1, 1);
      recieveHitBox.Start();

      // init health callbacks
      health.onHeal += () => { onHealCalled = true; };
      health.onDamage += () => { onDamageCalled = true; };
      health.onImmunity += () => { onImmunityCalled = true; };
      health.onMaxHealth += () => { onMaxHealthCalled = true; };
      health.onInjured += (Damage dt, CharacterHealth to) => { onInjuredCalled = true; };
      health.onHurt += (Damage dt, CharacterHealth to) => { onHurtCalled = true; };
      health.onDeath += () => { onDeathCalled = true; };
      health.onGameOver += () => { onGameOverCalled = true; };
      health.onInvulnerabilityStart += () => { onInvulnerabilityStartCalled = true; };
      health.onInvulnerabilityEnd += () => { onInvulnerabilityEndCalled = true; };
      health.onRespawn += () => { onRespawnCalled = true; };

    }
Exemplo n.º 2
0
    /// <summary>
    /// check missconfigurations and initialize
    /// </summary>
    public void Start() {
      Assert.IsNotNull(owner, "CharacterHealth owner is required: " + gameObject.name);

      damage = GetComponent<Damage> ();
      if (type == HitBoxType.DealDamage) {
        Assert.IsNotNull(damage, "Damage is require if type is DealDamage: " + gameObject.name);
      }

      body = GetComponent<BoxCollider2D>();
      Assert.IsNotNull(body, "BoxCollider2D is required: " + gameObject.name);

      if (type == HitBoxType.EnterAreas) {
        if (owner.character.enterAreas != null && owner.character.enterAreas != this ) {
          Debug.LogWarning("Only one EnterAreas HitBox is allowed!");
        }
        owner.character.enterAreas = this;
      }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Try to Damage the Character
    /// </summary>
    public void Damage(Damage dmg) {
      Debug.LogFormat("Object: {0} recieve damage {1} health {2} from: {3}",
        gameObject.name, dmg.amount, health, dmg.causer.gameObject.name);

      if (Damage(dmg.amount, dmg.type, dmg.causer)) {
        if (dmg.causer != null && dmg.causer.onHurt != null) {
          dmg.causer.onHurt(dmg, this);
        }
      }
    }
 /// <summary>
 /// Not used atm
 /// </summary>
 public virtual void OnInjuredCharacter(Damage dt, CharacterHealth h, Character to) {
   //Debug.LogFormat("hurt {1} with {2} damage", to.gameObject, dt.amount);
 }
Exemplo n.º 5
0
 void OnHurtCharacter(Damage dt, CharacterHealth to)
 {
     actionJump.ForceJump(new JumpConstant(character,
                                           jumpProperties.Clone((int)character.faceDir)
                                           ));
 }
 void OnHurtCharacter(Damage dt, CharacterHealth to) {
   actionJump.ForceJump(new JumpConstant(character,
     jumpProperties.Clone((int) character.faceDir)
   ));
 }