Example #1
0
    public void InstantiateBullet(Vector3 pos, Vector3 rot, float speed, float lifetime, string bulletId, float damage, int bulletTeam)
    {
        GameObject bullet;

        if (bulletTeam == Network.instance.player.GetTeamNumber())
        {
            bullet = GameObject.Instantiate(this.bulletPrefab, pos, Quaternion.Euler(rot));
        }
        else
        {
            bullet = GameObject.Instantiate(this.bulletEnemyPrefab, pos, Quaternion.Euler(rot));
        }
        //Rigidbody rigbod = bullet.GetComponent<Rigidbody>();
        //if (rigbod != null) rigbod.velocity = Vector3.forward*speed;
        //else Debug.LogError("Rigid body for bullet prefab spawn not found!");
        BulletScript bulletScript = bullet.GetComponent <BulletScript>();

        if (bulletScript != null)
        {
            bulletScript.SetSpeed(speed);
            bulletScript.lifeTime = lifetime;
            bulletScript.SetBulletId(bulletId);
            bulletScript.SetBulletDamage(damage);
            bulletScript.SetBulletTeam(bulletTeam);
        }
        else
        {
            Debug.LogError("BulletScript not found for bullet prefab!");
        }

        if (bulletScript != null)
        {
            Bullets.Add(bulletId, bullet);
        }
    }