Exemple #1
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Initializes the projectile, usually called
    //  when it is being reused from an object pool
    /// </summary>
    public void Init(Weapon wep)
    {
        // Reset stats
        _DistanceTravelled = 0f;
        _WeaponAttached    = wep;
        _Velocity          = transform.forward;
        _OriginPosition    = transform.position;
        _Damages           = wep.Damages;

        // This should already be called when it is pulled from its object pool,
        // but this is just incase it somehow isn't
        gameObject.SetActive(true);

        // Set homing target for tracking
        _HomingProjectile = wep.TrackingProjectile;
        _TrackingStrength = wep.TrackingStrength;
        if (_HomingProjectile)
        {
            if (_WeaponAttached.GetUnitAttached() != null)
            {
                HomingTarget = _WeaponAttached.GetUnitAttached().GetAttackTarget();
            }
            if (_WeaponAttached.GetTowerAttached() != null)
            {
                HomingTarget = _WeaponAttached.GetTowerAttached().GetAttackTarget();
            }

            // Set distance for tracking unlock
            _DisableTrackDistance = Vector3.Distance(_OriginPosition, HomingTarget.transform.position);
        }
        else
        {
            _DisableTrackDistance = 100000f;
        }

        // Create parabolic arc component
        ParabolicArc oldArc = GetComponent <ParabolicArc>();

        if (oldArc != null)
        {
            Destroy(oldArc);
        }
        if (AffectedByGravity)
        {
            gameObject.AddComponent <ParabolicArc>();
        }

        // Timed detonation
        if (TimedDetonation)
        {
            StartCoroutine(DetonatorTimer());
        }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Initializes the projectile, usually called
    //  when it is being reused from an object pool
    /// </summary>
    public void Init(Weapon wep)
    {
        // Reset stats
        _DistanceTravelled = 0f;
        _WeaponAttached    = wep;
        _Velocity          = transform.forward;
        _OriginPosition    = transform.position;
        _Damages           = wep.Damages;

        // This should already be called when it is pulled from its object pool,
        // but this is just incase it somehow isn't
        gameObject.SetActive(true);

        // Set homing target for tracking
        if (HomingProjectile)
        {
            if (_WeaponAttached.GetUnitAttached() != null)
            {
                HomingTarget = _WeaponAttached.GetUnitAttached().GetAttackTarget();
            }
            if (_WeaponAttached.GetTowerAttached() != null)
            {
                HomingTarget = _WeaponAttached.GetTowerAttached().GetAttackTarget();
            }
        }

        // Create parabolic arc component
        ParabolicArc oldArc = GetComponent <ParabolicArc>();

        if (oldArc != null)
        {
            Destroy(oldArc);
        }
        if (AffectedByGravity)
        {
            gameObject.AddComponent <ParabolicArc>();
        }
    }