Search Unity

flamethrower 2D not hitting all enemies

Discussion in '2D' started by willianbrasil, Feb 10, 2018.

  1. willianbrasil

    willianbrasil

    Joined:
    Oct 17, 2017
    Posts:
    5
    Hi, i have a script for the flame of my flamethrower and i've debugged all i could i'm using unity remote to test, idk if could cause this, i have a turret that fires like a flamethrower and damage target's every 0.4 seconds using ontriggerstay2d and 4 enemies in front of it, sometimes hits do not land on 1, 2 or 3 of them i've tried to check if any boxes were off at the time, or if anything was disabled and nothing so here's my code.

    Code (csharp):
    1.  void FixedUpdate() {
    2.          if (dot_timer > 0)
    3.              dot_timer -= Time.deltaTime;
    4.          else
    5.          {
    6.              dot_timer = base_dot_timer;
    7.              Debug.Log("should hit");
    8.              Debug.Break();
    9.          }
    10.      }
    11.  
    12.      private void OnTriggerStay2D(Collider2D other)
    13.      {
    14.          if (dot_timer <= 0)
    15.          {
    16.              if (other.gameObject.layer == target_layer)
    17.              {
    18.                  Enemy_Manager enemy = other.gameObject.GetComponent<Enemy_Manager>();
    19.                  enemy.Hp -= damage;
    20.                  Debug.Log("hit");
    21.                  enemy.Blink_fx.SetActive(true);
    22.                  Vector3 screenPoint = Camera.main.WorldToViewportPoint(other.gameObject.transform.position);
    23.                  bool onScreen = screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
    24.                  if (onScreen)
    25.                  {
    26.                      for (sbyte i = 0; i < 30; i++)
    27.                      {
    28.                          if (!game_manager.TextInstPool.activeInHierarchy)
    29.                          {
    30.                              game_manager.TextInstPool.transform.position = other.gameObject.transform.localPosition;
    31.                              game_manager.TextInstPool.SetActive(true);
    32.                              game_manager.TextPool.text = damage.ToString();
    33.                              break;
    34.                          }
    35.                      }
    36.  
    37.                  }
    38.              }
    39.          }
    40.      }