#Machine gun script. timer.

1 messages · Page 1 of 1 (latest)

tough stream
#

It's getting really crowded in there.

fierce bison
#

I don't remember volunteering to help, but I guess I can 😛

#

I was just trying to clear up communication confusion

tough stream
#

You don't have to.

#

im not forcing you to do anything

fierce bison
#

shrug, should be pretty simple - let's see the current script?

tough stream
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class fireBullet : MonoBehaviour
{
   public GameObject projectile;
   public float launchVelocity = 1000f;
   void Update()
   {
       private float timr;
        timr += Time.deltaTime;
        if(timr >= 0.5f)
        {
            timr = 0;
        }
       if (Input.GetButton("Fire1"))
       {
           GameObject ball = Instantiate(projectile, transform.position,transform.rotation);
           ball.GetComponent<Rigidbody>().AddRelativeForce(new Vector3(0, 0,-launchVelocity));
       }
       
   } 
}
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class fireBullet : MonoBehaviour
{
   public GameObject projectile;
   public float launchVelocity = 1000f;
   public float timr;
   void Update(){
       
        timr += Time.deltaTime;
        if(timr >= 0.5f)
        {
            timr = 0;
           if (Input.GetButton("Fire1")){
                GameObject ball = Instantiate(projectile, transform.position,transform.rotation);
                ball.GetComponent<Rigidbody>().AddRelativeForce(new Vector3(0, 0,-launchVelocity));
           }
        }
        
      
    }
}
#

got it

fierce bison
#

hehe got it, I had to overhaul it quite a bit

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class fireBullet : MonoBehaviour
{
    public GameObject projectile;
    public float launchVelocity = 1000f;

    public float timr = float.NegativeInfinity;
    
    void Update()
    {
        if (timr > float.NegativeInfinity)
        {
            timr += Time.deltaTime;
        }

        if (Input.GetButtonDown("Fire1"))
        {
            timr = 0;
        }
if (Input.GetButton("Fire1"))
{

            if (timr >= 0.1f) { 
    GameObject ball = Instantiate(projectile, transform.position, transform.rotation);
    ball.GetComponent<Rigidbody>().AddRelativeForce(new Vector3(0, 0, -launchVelocity));
                timr = 0;
}
       
   } 

if (Input.GetButtonUp("Fire1"))
        {
            timr = float.NegativeInfinity;
        }

}```
#

untested, but should work.. maybe

#

try er out 😛

#

should be on a 1/10 second delay

fierce bison
#

Ohhh you just put it up into the if

#

ye, works