protected override void Initialize() { base.Initialize(); DamageOnHit doh = GetComponent <DamageOnHit>(); doh.onHitOccured += GainExperience; targetSelectors.Add(new TargetSelection()); //immediate hit object TargetSelectionOnCollision targetSelection = GetComponent <TargetSelectionOnCollision>(); targetSelection.Selectors = targetSelectors; targetSelection.Effects = impactEffects; targetSelection.onHitOccured += GainExperience; targetSelection.CollisionLayer = collisionLayer; }
private void InitializePool() { pool = new ObjectPool(vfxNumber); for (int i = 0; i < vfxNumber; i++) { //shot gets a shot prefab that needs to be instantiated GameObject bullet = Instantiate(vfx); bullet.SetActive(false); //rigidbody is needed to perform collision detection //as we might re-use the bullet prefab for other purposes //the rigidbody is added dynamically Rigidbody rb = bullet.AddComponent <Rigidbody>(); //disable gravity as the shot should fly straight forward rb.useGravity = false; //prepare collision handler TargetSelectionOnCollision collisionSelection = bullet.AddComponent <TargetSelectionOnCollision>(); //add the set up target selection methods and impact effects //references to the lists are passed as content changes are //propagated immediately collisionSelection.Selectors = targetSelectors; collisionSelection.Effects = impactEffects; collisionSelection.CollisionLayer = collisionLayer; //straight forward movement LinearMovement movement = bullet.AddComponent <LinearMovement>(); //stop movement on hit collisionSelection.onHitOccured += movement.StopMovement; //if skill can level if (skillExperience != null) { //get experience on successful hit collisionSelection.onHitOccured += GainExperience; } pool.AddObject(bullet); } skillExperience.onLevelChanged += LevelUpHandler; }