i have 2 question
first about Bools
i didnt figure out how to make a bool that when activated it desactivats other active bools (this is for multiple crosshairs )
if(Default_CrossHairBool)
{
Default_CrossHair.gameObject.SetActive(true);
TreeCrosshairbool = false;
WoodCrosshairBool = false;
}
else
{
Default_CrossHair.gameObject.SetActive(false);
}
if (TreeCrosshairbool )
{
TreeCrosshair.gameObject.SetActive(true);
Default_CrossHairBool = false;
WoodCrosshairBool = false;
}
else
{
TreeCrosshair.gameObject.SetActive(false);
}
if(WoodCrosshairBool)
{
WoodCrosshair.gameObject.SetActive(true);
Default_CrossHairBool = false;
TreeCrosshairbool = false;
}
else
{
WoodCrosshair.gameObject.SetActive(false);
}
firstly its not doing its job … i know what s wrong but i cant solve it and i dont like this script it s too long and due to my low Scirpting knowledge i cant make it better
second Question
is
Second question is i have a raycast when i get closer to something i can change the crosshair but when im out of range the crosshair doesnt change to default one
RaycastHit hit;
Vector3 rayOrigin = fpscam.ViewportToWorldPoint(new Vector3(.5f, .5f, 0));
if (Physics.Raycast(rayOrigin, fpscam.transform.forward, out hit, RayRange))
{
//check if the it s a tree
if (hit.collider.CompareTag("Tree"))
{
//change Crosshair
CrossHairMang.TreeCrosshairbool = true;
CrossHairMang.Default_CrossHairBool = false;
CrossHairMang.WoodCrosshairBool = false;
Debug.Log("whaz0");
if (Input.GetButtonDown("Fire1") && Time.time > NextTimeHit)
{
// Hit the tree
NextTimeHit = Time.time + hitRate;
print(NextTimeHit);
treeState = hit.collider.gameObject.GetComponent<TreeState>();
treeState.THealth -= TreeDamage;
print("u hit a tree");
}
}
//Still in raycast If Statment
if (hit.distance > RayRange)
{
// now if Out of range change the crosshair to default one
CrossHairMang.Default_CrossHairBool = true;
CrossHairMang.TreeCrosshairbool = false;
CrossHairMang.WoodCrosshairBool = false;
}
}