예제 #1
0
    public Bullet_generic request_blt()
    {
        if (bullet_pool.Count <= 0)
        {
            return(null);
        }
        Bullet_generic ret = bullet_pool[0];

        bullet_pool.RemoveAt(0);

        ret.gameObject.SetActive(true);
        ret.reset();
        return(ret);
    }
예제 #2
0
    void fire_bullet(GameObject activator, Vector2 fire_point, float blt_dir, bool hasAuthority, float lag_prediction = 0)
    {
        //Withdraw from pool
        Bullet_generic the_bullet = Pool_watcher.Singleton.request_blt();

        //Get new ones
        if (the_bullet == null)
        {
            the_bullet = Instantiate(this.bullet, fire_point, Quaternion.identity).GetComponent <Bullet_generic>();
            the_bullet.pool_watcher     = Pool_watcher.Singleton;
            the_bullet.initial_hit_fltr = the_bullet.hit_fltr;
            the_bullet.default_gradient = the_bullet.GetComponent <TrailRenderer>().colorGradient;
            the_bullet.default_texture  = the_bullet.GetComponent <TrailRenderer>().material.mainTexture;
        }
        else
        {
            the_bullet.GetComponent <TrailRenderer>().Clear();
            the_bullet.transform.position = fire_point;
        }
        the_bullet.aimdir = (new Vector2(Mathf.Cos(blt_dir * Mathf.PI / 180), Mathf.Sin(blt_dir * Mathf.PI / 180))).normalized;
        the_bullet.GetComponent <TrailRenderer>().widthMultiplier = blt_mass / 20;
        the_bullet.mass         = blt_mass;
        the_bullet.speed        = blt_speed;
        the_bullet.speed_muzzle = blt_speed;
        the_bullet.speed_damp   = blt_speed_damp;
        the_bullet.speed_min    = blt_speed_min;
        the_bullet.spark        = spark;
        the_bullet.activator    = activator;
        the_bullet.local        = hasAuthority;
        the_bullet.isDedicated  = cvar_watcher.isDedicated();
        the_bullet.lag_comp     = lag_prediction;
        //Remove hit collision for ally if server flag is off
        if (cvar_watcher.allyBulletPassThru)
        {
            the_bullet.hit_fltr.value = the_bullet.initial_hit_fltr.value - (1 << activator.GetComponent <Body_generic>().hitbox_main.gameObject.layer);
        }

        //Customize color
        if (blt_custom)
        {
            the_bullet.GetComponent <TrailRenderer>().colorGradient = blt_color;
            if (blt_texture != null)
            {
                the_bullet.GetComponent <TrailRenderer>().material.mainTexture = blt_texture;
            }
        }
        //the_bullet.lag_sim(lag_prediction);
    }
예제 #3
0
    void shoot()
    {
        //Debug.Log("bullet");
        //Withdraw from pool
        Bullet_generic the_bullet = Pool_watcher.Singleton.request_blt();

        //Get new ones
        if (the_bullet == null)
        {
            the_bullet = Instantiate(bullet, transform.position, Quaternion.identity).GetComponent <Bullet_generic>();
            the_bullet.pool_watcher     = Pool_watcher.Singleton;
            the_bullet.initial_hit_fltr = the_bullet.hit_fltr;
            the_bullet.default_gradient = the_bullet.GetComponent <TrailRenderer>().colorGradient;
            the_bullet.default_texture  = the_bullet.GetComponent <TrailRenderer>().material.mainTexture;
        }
        else
        {
            the_bullet.GetComponent <TrailRenderer>().Clear();
            the_bullet.transform.position = transform.position;
        }
        Vector2 aimdir = (Target.position - transform.position).normalized;
        float   angle  = Mathf.Atan2(aimdir.y, aimdir.x) + UnityEngine.Random.Range(-BulletSpread, BulletSpread) * 3.14f / 180;

        the_bullet.aimdir = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
        the_bullet.GetComponent <TrailRenderer>().widthMultiplier = bullet_mass / 20;
        the_bullet.mass         = bullet_mass;
        the_bullet.speed        = bullet_speed;
        the_bullet.speed_muzzle = bullet_speed;
        the_bullet.speed_damp   = bullet_damp;
        the_bullet.speed_min    = bullet_speed_min;
        the_bullet.spark        = spark;
        the_bullet.activator    = gameObject;
        the_bullet.local        = isServer;
        the_bullet.isDedicated  = Server_watcher.Singleton.isDedicated();
        the_bullet.lag_comp     = Server_watcher.Singleton.local_player.latency / 2;
        the_bullet.noDamage     = noDamage;
        //Customize color
        the_bullet.GetComponent <TrailRenderer>().colorGradient = Tracer;
    }
예제 #4
0
 public void recycle_blt(Bullet_generic blt)
 {
     bullet_pool.Add(blt);
     blt.gameObject.SetActive(false);
 }