I want to reveal a specific arrow pointing at a specific location using the ArrowOnOff code when the timer variable in CheckpointTimer turns to 0.
However, I can’t figure out how to connect the two scripts to get this working. (My implementation of finding/revealing arrows in ArrowOnOff isn’t the best, I know - I plan to ask a separate question for that, so please don’t focus on it.)
Here are my scripts:
ArrowOnOff.cs:
using UnityEngine;
using System.Collections;
public class ArrowsOnOff : MonoBehaviour {
// Use this for initialization
void Start () {
GameObject.Find ("Arrow1").transform.localScale = new Vector3(0, 0, 0);
GameObject.Find ("Arrow (2)").transform.localScale = new Vector3(0, 0, 0);
/*
[...]
*/
GameObject.Find ("Arrow (28)").transform.localScale = new Vector3(0, 0, 0);
GameObject.Find ("Arrow (21)").transform.localScale = new Vector3(0, 0, 0);
}
// Update is called once per frame
void Update () {
}
//-------
void OnTriggerEnter(Collider col)
{
if (col.tag == "1")
{
Debug.Log ("hit");
GameObject.Find ("Arrow1").transform.localScale = new Vector3(1, 1, 1);
}
///---------
if (col.tag == "2")
{
Debug.Log ("hit");
GameObject.Find ("Arrow (2)").transform.localScale = new Vector3(1, 1, 1);
}
/*
[...]
*/
if (col.tag == "30")
{
Debug.Log ("hit");
GameObject.Find ("Arrow (28)").transform.localScale = new Vector3(1, 1, 1);
}
///---------
if (col.tag == "24AGAIN")
{
Debug.Log ("hit");
GameObject.Find ("Arrow (21)").transform.localScale = new Vector3(1, 1, 1);
}
/// -------
}
//--------------------------------------------------------
void OnTriggerExit(Collider col)
{
if (col.tag == "1")
{
GameObject.Find ("Arrow1").transform.localScale = new Vector3(0, 0, 0);
Debug.Log ("Left");
}
///---------
if (col.tag == "2")
{
Debug.Log ("hit2");
GameObject.Find ("Arrow (2)").transform.localScale = new Vector3(0, 0, 0);
}
/*
[...]
*/
if (col.tag == "30")
{
Debug.Log ("hit");
GameObject.Find ("Arrow (28)").transform.localScale = new Vector3(0, 0, 0);
}
/// -------
if (col.tag == "24AGAIN")
{
Debug.Log ("hit");
GameObject.Find ("Arrow (21)").transform.localScale = new Vector3(0, 0, 0);
}
}
//----------
}
CheckpointTimer.cs:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class CheckpointTimer : MonoBehaviour {
public Text timerText;
public int startTime = 3;
private float timer;
public GameObject greenImage;
public GameObject redImage;*
// Use this for initialization
void Start () {
timer = startTime;
}
// Update is called once per frame
void Update () {
if (entered) {
timer -= Time.deltaTime;
timerText.text = timer.ToString ("0");
if (timer <= 0) {
player.GetComponent<OVRPlayerController> ().Acceleration = 0.1f;
timer = startTime;
entered = false;
redImage.SetActive (false);
greenImage.SetActive (true);
}
}
}
bool entered = false;
GameObject player;
void OnTriggerEnter(Collider collider) {
if (collider.gameObject.tag == "Player") {
player = collider.gameObject;
player.GetComponent<OVRPlayerController> ().Acceleration = 0;
entered = true;
redImage.SetActive (true);
greenImage.SetActive (false);
}
}
void OnTriggerExit(Collider collider) {
timer = startTime;
timerText.text = "";
entered = false;
greenImage.SetActive (false);
}
}