private void OnTriggerEnter2D(Collider2D collision) { Attacker_TypeA attacker = collision.gameObject.GetComponent <Attacker_TypeA>(); Health health = collision.GetComponent <Health>(); if (attacker && health) { health.DamageReceived(damage); Destroy(gameObject); } }
bool isTimeToSpawn(GameObject attackerGameObject) { Attacker_TypeA attackerA = attackerGameObject.GetComponentInChildren <Attacker_TypeA>(); float spawnDelay = attackerA.spawnEverySecond; float spawnPersecond = 1 / spawnDelay; if (Time.deltaTime > spawnDelay) { Debug.LogWarning("Spawn rate capped by frame rate and that's bad"); } float threshold = spawnPersecond * Time.deltaTime / 5; //we have 5 lanes return(Random.value < threshold); //Always make it clear to read }
// Use this for initialization void Start() { targetAnimation = GetComponent <Animator>(); attackerA = GetComponent <Attacker_TypeA>(); }