Quantcast
Channel: Questions in topic: "timers"
Viewing all articles
Browse latest Browse all 134

Detecting a Continuous Collision/Player Position and Reseting Timers,Detect a collision for a certain number of seconds

$
0
0
Hi all, I've been tearing my hair out with this, and while there seem to be a few very similar questions out there I've yet to really figure this out. The setting: The player needs to remain in a certain area for 3 seconds in order to take a photo. Currently I'm using a plane with a mesh trigger as the 'photo zone.' If they stay touching the plane for 3 seconds, the photo is taken (i.e. bool photoTaken = true). If they leave the photo zone before the 3 seconds are up, the timer resets. I found a very similar question [here][1] and used that code to get started. It *basically* works, but annoyingly photo-taking 'process' seems to start every frame, leading to enormous spam in the console. **I'd like to have the process start once for each entrance into the zone, rather than firing continuously.** I'm pretty new to Unity and C# so I'm sure I'm doing something a bit silly. Posting my code (attached to the player GameObject, minus other things like movement for brevity) for reference. Thanks in advance for any advice you might have! using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public bool photoTaken = false; public float photoCountdown = 3.0f; public bool inPhotoZone = false; // Start is called before the first frame update void Start() { playerRb = GetComponent(); } // Update is called once per frame void Update() { // Collision timer if (inPhotoZone == true) { photoCountdown -= Time.deltaTime; if (photoCountdown

Viewing all articles
Browse latest Browse all 134

Latest Images

Trending Articles





Latest Images