private void OnTriggerStay2D(Collider2D collision) { pharoahMove ph = GetComponentInParent <pharoahMove>(); if (collision.gameObject.tag == "Dean" && Time.time > fire && ph.pharoahMovingLeft == true) { fire = Time.time + fireRateSpear; ShootingScript shootScript = GetComponent <ShootingScript>(); shootScript.enemySpearLeft(); } }
private void OnTriggerStay2D(Collider2D collision) { //First we call the parent's script pharoahMove ph = GetComponentInParent <pharoahMove>(); //if the collider is touching dean and the time is greater than last fired. Now if the pharoah is moving right from the parent script then if (collision.gameObject.tag == "Dean" && Time.time > fire && ph.pharoahMovingRight == true) { //the fire float is now time + the firerate of the spear fire = Time.time + fireRateSpear; //call the shooting script and make the pharoah throw the spear ShootingScript shootScript = GetComponent <ShootingScript>(); shootScript.enemySpearRight(); } }