i tried to make my gun not fire while the game is paused becasue the gun fires by using update to detect a mouse click but its not working here is my code:
using System.Collections;
using UnityEngine;
public class gunfire : MonoBehaviour
{
public Transform chargeSpawn;
public GameObject bubble;
public GameObject growingBubble;
public float growRate = 0.025f;
public float damage;
public int damageModifier = 2;
PauseMenu pausemenu;
public Transform spawnpoint;
public bool isGrowing = false;
IEnumerator growCoroutine;
void Start()
{
growCoroutine = growCor();
}
public void firePause(PauseMenu pausemenu) {
this.pausemenu = pausemenu;
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (pausemenu.gameIsPaused == false)
{
}
else {
growingBubble = Instantiate(bubble, spawnpoint.position, spawnpoint.rotation);
growStart();
}
}
if (Input.GetMouseButtonUp(0))
{
growStop();
bubble.transform.localScale = new Vector3(1f, 1f, 1f);
}
}
IEnumerator growCor()
{
while (isGrowing)
{
growingBubble.transform.localScale += Vector3.one * growRate;
growingBubble.transform.position = spawnpoint.position;
var radius = growingBubble.transform.localScale.y;
if (radius >= 4)
{
growStop();
}
yield return null;
}
}
void growStart() {
if (!isGrowing) {
isGrowing = true;
StartCoroutine(growCoroutine);
}
}
void growStop() {
if (isGrowing)
{
StopCoroutine(growCoroutine);
isGrowing = false;
Vector3 explosionPos = growingBubble.transform.position;
var radius = growingBubble.transform.localScale.y;
float speed = ((400 / radius));
damage = (damageModifier*radius);
Rigidbody projectile = growingBubble.GetComponent();
projectile.velocity = transform.TransformDirection(new Vector3(speed, 0, 0));
projectile.AddExplosionForce(5f, explosionPos, 5f, 0f);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Projectile")
{
Physics.IgnoreCollision(growingBubble.GetComponent(), growingBubble.GetComponent());
}
}
}
does anyone see what is wrong or have a better idea
↧