namespace Opsive.UltimateCharacterController.Objects.ItemAssist
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.Shared.Game;
using Opsive.UltimateCharacterController.Items.Actions;
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
using Opsive.UltimateCharacterController.Networking.Game;
#endif
using Opsive.UltimateCharacterController.Objects;
public class HitByMagic : MagicProjectile
{
private void ReturnToObjectPool()
{
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
if (NetworkObjectPool.IsNetworkActive()) {
// The object may have already been destroyed over the network.
if (!m_GameObject.activeSelf) {
return;
}
NetworkObjectPool.Destroy(m_GameObject);
return;
}
#endif
ObjectPool.Destroy(m_GameObject);
}
protected override void OnCollision(RaycastHit? hit)
{
// NEW CODE STARTS
if (hit.Value.transform.gameObject.layer == 26)
{ // Check if target is Enemy
var characterLocomotion = hit.Value.transform.gameObject.GetComponent<UltimateCharacterLocomotion>();
var jumpAbility = characterLocomotion.GetAbility<Jump>();
characterLocomotion.TryStartAbility(jumpAbility);
}
// NEW CODE ENDS
m_MagicItem.PerformImpact(m_CastID, m_GameObject, hit.Value.transform.gameObject, hit.Value);
// Destroys the projectile when it has collided with an object.
if (m_DestroyOnCollision)
{
// The projectile can wait for any particles to stop emitting.
var immediateDestroy = !m_WaitForParticleStop;
if (!immediateDestroy)
{
var particleSystem = m_GameObject.GetCachedComponent<ParticleSystem>();
if (particleSystem != null)
{
particleSystem.Stop(true, ParticleSystemStopBehavior.StopEmitting);
Scheduler.Schedule(particleSystem.main.duration, ReturnToObjectPool);
immediateDestroy = false;
}
}
if (immediateDestroy)
{
ReturnToObjectPool();
}
else
{
// The projectile is waiting on the particles to be destroyed. Stop moving.
Stop();
}
}
}
}
}