Ejemplo n.º 1
0
    GameObject InstantiateProjectileWithoutCollider(Vector3 source, Vector3 force, Vector3 currentShooterSpeed, string shooterId, string projectileId, bool seeking, string targetUserId)
    {
        // TODO: Once again, find why these are sometimes null..
        if (activeProjectiles == null)
        {
            Debug.LogWarning("activeProjectiles is null!");
            InitActiveProjectileDict();
        }
        GameObject projectileObj = Instantiate(projectilePrefab, source, Quaternion.identity);

        activeProjectiles[projectileId] = projectileObj;
        projectileObj.GetComponent <Rigidbody>().velocity = seeking ?
                                                            force.normalized :
                                                            currentShooterSpeed;
        projectileObj.GetComponent <Rigidbody>().AddForce(force, ForceMode.Impulse);
        Projectile projectile = projectileObj.GetComponent <Projectile>();

        projectile.shooterId    = shooterId;
        projectile.projectileId = projectileId;
        projectile.lockedOn     = seeking;
        if (seeking)
        {
            // Set initial transform to align to correct direction
            projectile.transform.up = force.normalized;
            foreach (Player player in PhotonNetwork.PlayerList)
            {
                if (player.UserId == targetUserId)
                {
                    projectile.target = NetworkCharacter.GetTargetableCharacter(player);
                    break;
                }
            }
        }
        return(projectileObj);
    }