public void SpawnFireBall() { if (fireBall != null) { GameObject ball = Instantiate(fireBall, transform.position, Quaternion.identity); FireBall fir = ball.GetComponent <FireBall>(); Transform t = FindClosestTarget(); fir.SetDamage(damage); if (t != null) { // note t may be destroyed fir.SetDirection(-(transform.position - t.position)); } } }