Code for seperate clear area

As my hair started falling because of problems with OnTriggerStay, i went and ripped Clear area collider box and just placed it on spot i wanted it on map. Made code in it to check if player is in area, and if player called heli or not.

Here is code for ClearArea.cs i made if anyone is interested about different solution (will change debug.log test stuff to UI Texts later):

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

public class ClearArea : MonoBehaviour {

public bool heliCalled = false;
public bool playerOnClearArea = false;
public HeliRadio heliradio;


void OnTriggerEnter (Collider other)
{
	if (other.tag == "Player") {
		playerOnClearArea = true;
		Debug.Log("Good area for calling Helo!");
	}

}

void OnTriggerExit (Collider other)
{
	if (other.tag == "Player" && !heliCalled) {
		playerOnClearArea = false;
		Debug.Log("Forgot to call helo!");
	}
}
// Update is called once per frame
void Update ()
{
	if (Input.GetButtonDown("CallHeli") && !heliCalled && playerOnClearArea == true) {
	heliradio.Call();
	heliCalled = true;
	}
}

}

2 Likes

Privacy & Terms