Exemple #1
0
    protected virtual void FireProjectile()
    {
        //doesn't fire if fire button isn't set or the gun is still cooling down
        if (!Input.GetButton("Fire1") || (getCurrentMS() - lastFireMS) < coolDownMS)
        {
            return;
        }


        GameObject bullet = pgo.GetPooledObject(bulletId);

        bullet.transform.position = transform.position;
        bullet.transform.rotation = transform.rotation;
        bullet.SetActive(true);

        bullet.GetComponent <Rigidbody>().velocity = playerCam.transform.forward; //speed multiplier added inside bullet object.
        bullet.GetComponent <Bullet>().Reset();


        lastFireMS = getCurrentMS();
    }
    // Call for each frame
    void Update()
    {
        //Check if the player hit the fire button
        if (Input.GetButton("Fire1") && can_fire == 1)
        {
            GameObject CR = pgo.GetPooledObject(bulletId);
            CR.transform.position = transform.position;
            CR.transform.rotation = transform.rotation;
            CR.SetActive(true);
            //GameObject CR = Instantiate(Rocket, transform.position, transform.rotation);        //Instantiate the rocket object at current position and current angle
            CR.GetComponent <Rigidbody>().velocity = transform.forward * rocket_speed;       //Set the speed
            can_fire = 0;
        }

        if (can_fire == 0)
        {
            fire_rate -= Time.deltaTime;
            if (fire_rate <= 0)
            {
                fire_rate = 0.1f;
                can_fire  = 1;
            }
        }
    }