I’m trying to simulate an LED turning on by enabling a light when another object is close to a given position.
using UnityEngine;
using System.Collections;
public class Activate14 : MonoBehaviour {
public GameObject player;
public ImageTargetBehaviour myTarget;
private NextButton2 playerScript;
void Start () {
playerScript = player.GetComponent<NextButton2> ();
}
// Update is called once per frame
void LateUpdate () {
var pos = GameObject.Find("StopWire07").transform.position;
Debug.Log (pos);
if(myTarget.CurrentStatus == TrackableBehaviour.Status.TRACKED && playerScript.nextcounter >= 14) {
Debug.Log ("14 On");
//renderer.enabled = true;
light.enabled = true;
}
if(playerScript.nextcounter < 14) {
Debug.Log ("14 Off");
//renderer.enabled = false;
light.enabled = false;
}
}
}
The code above currently enables my light when my Image Target is being tracked and when my counter is 14 or greater. It also returns the position of the object “StopWire07” as -588.8, 6.4, -549.1
What I want to do is add another condition to enabling the light. I want that condition to be that StopWire07 is in (or close to) the position indicated above. That start position will be a constant and will not need to update dynamically.
This way I’m hoping that when StopWire07 moves out of position, the light will be disabled. And when it moves into position, it will be enabled.
The problem I’m having is that I am very new to C# and I am unsure how to compare the current position with a constant, as well as how to included a plus/minus factor as I do not expect the object to be placed exactly back where it was.