Hey. So I have a public bool assigned to the public bool from a script connected with another gameObject. I want to change the boolean value of the remote script when my raycast encounters an “enemy” tag. After testing I’ve determined that I am getting the true value of BattleTime.On() and that my raycasting is working as intended, but I cannot alter the value of BattleTime.On().
Here is my player script:
public bool battletime;
public void Update() {
battletime = GameObject.Find("Manager").GetComponent<BattleTime>().on;
RaycastHit hitInfo1;
Ray ray = new Ray (transform.position, new Vector3(0,0,-1));
if (Physics.Raycast (ray, out hitInfo1, Mathf.Infinity)) {
if (hitInfo1.collider.gameObject.CompareTag ("enemy")) {
//Physics2D.Raycast (ray1, out hitInfo1, Mathf.Infinity)) {
battletime = true;
Debug.Log (battletime);
}} else {
battletime = false;
Debug.Log (battletime);
}
And here is the constant script, located in the Manager gameObject:
public bool on;
void Update(){
if (on == true)
Debug.Log ("it is true");
else
Debug.Log ("lies");
}
Turning ‘on’ into a static script does not help. Anyone got any ideas?