#Machine gun script. timer.
1 messages · Page 1 of 1 (latest)
I don't remember volunteering to help, but I guess I can 😛
I was just trying to clear up communication confusion
shrug, should be pretty simple - let's see the current script?
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
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
the one above works too