Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

when float is less then zero, do action once

$
0
0
I'm making a game where time slows down when you aim. There's a timer so that you can't aim forever. When the timer goes off, I want the gun to move to the right once, but I can't seem to figure it out. I'm fairly new to Unity, so any help would be appreciated. Here's the code: public float currentAim; public float aimWait; public bool gunAiming; public bool gunTimeout; public bool gunMoved; public bool gunMovedTrue; void Start() { currentAim = maxAim; gunAiming = false; aimWait = 1f; gunMoved = false; } // Update is called once per frame void Update() { if(Input.GetKeyDown(KeyCode.Mouse0)) { Shoot(); } if(currentAim <= 0 && gunMovedTrue) { gunMoved = true; gunMovedTrue = false; } else { gunMoved = false; } if(currentAim <= 0) { //make guntimeout always true gunTimeout = true; //make gunmoved true once and then false // gunMoved = true; } else { gunTimeout = false; gunMoved = false; } if(gunTimeout) { gunMovedTrue = true; } if(Input.GetKeyDown(KeyCode.Mouse1)) { gun.transform.Translate(Vector3.right); gunAiming = true; } if (Input.GetKeyUp(KeyCode.Mouse1)) { gun.transform.Translate(Vector3.left); gunAiming = false; } Aim(); if (Input.GetKey(KeyCode.Mouse1)) { gunAiming = true; } else { gunAiming = false; } } void Aim() { if (gunAiming) { if (gunTimeout) { if (gunMoved) { gun.transform.Translate(Vector3.left); gunMoved = false; } else { Time.timeScale = 1f; camera.fieldOfView = 60; } } else { Time.timeScale = 0.1f; camera.fieldOfView = 45; currentAim -= Time.deltaTime * 10; } }

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>