Пример #1
0
    public static IProjectile FireProjectile(Entity creator, Rigidbody projectilePrefab, Transform fireTransform,
                                             Vector3 destination, float secondsToFlyHorizontalMeter)
    {
        // EARLY OUT! //
        if (creator == null || projectilePrefab == null || fireTransform == null)
        {
            return(null);
        }

        // Create an instance of the shell and store a reference to it's rigidbody.
        Rigidbody projectileRigidbody =
            Utils.Instantiate(projectilePrefab, fireTransform.position, fireTransform.rotation);

        projectileRigidbody.transform.SetParent(SL.Get <GameModel>().BoardRoot.transform, worldPositionStays: true);

        Vector3 velocity = CombatUtils.CalculateVelocityToHit(
            fireTransform.position,
            destination,
            secondsToFlyHorizontalMeter);

        projectileRigidbody.AddForce(velocity, ForceMode.VelocityChange);

        var projectile = projectileRigidbody.gameObject.GetInterface <IProjectile>();

        if (projectile != null)
        {
            projectile.Init(creator);
        }
        else
        {
            Debug.LogWarning("Problem with the projectile setup.");
        }

        return(projectile);
    }