So essential I need assistance in updating a private bool from a public bool of another script; The following is the first script which has the hitComm bool updating properly when a click is detected
public bool hitComm;
public Transform thisTransform;
private bool hitVerify = false;
void Awake () {
hitComm = hitVerify;
}
void Update () {
//Raycaster
Ray constantRay = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(constantRay.origin,constantRay.direction * 100,Color.red);
if (Input.GetMouseButtonDown(0))
{
RaycastHit2D hit = Physics2D.GetRayIntersection(constantRay,Mathf.Infinity);
if(hit.collider != null && hit.collider.transform == thisTransform)
{
hitVerify = true;
hitComm = hitVerify;
} else{
hitVerify = false;
hitComm = hitVerify;
}
Debug.Log("hitComm: " + hitComm);
}
hitComm = hitVerify;
}
This is the second script, the one I am having trouble with attaining the proper updated bool state from the first script hitComm var.
using UnityEngine;
using System.Collections;
public class HitTest : MonoBehaviour {
public CharacterClick greenLight;
private bool hitChecker;
// Use this for initialization
void Start () {
renderer.material.color = new Color(1,0,0);
greenLight = new CharacterClick();
}
// Update is called once per frame
void Update () {
hitChecker = greenLight.hitComm;
if(Input.GetMouseButtonDown(0))
{
Debug.Log("hitChecker: " + hitChecker);
if(hitChecker)
{
renderer.material.color = new Color(0,1,0);
} else if (!hitChecker){
renderer.material.color = new Color(1,0,0);
}
}
}
}
So the hitChecker here which is supposed to be referencing hitComm from the other script, with every Update, it does not reapply the value state of what hitComm is. I really appreciate some help on this.
Here’s a visual: