I have a script that needs to set a variable to true if Raycast is hitting a gameObject with tag and false if it is not , The issue is if I move the Generator object or the thing it is hitting and the Raycast is not hitting it anymore the variable is not changing to false
private var Generator : GameObject;
public var Power : float = 100;
public var Current : float = 20;
public var CanGivePower : boolean = false;
public var GivingPower : boolean = false;
public var HitObject;
function Start () {
}
function FixedUpdate () {
var fwd = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
Debug.DrawRay(transform.position, fwd * 2, Color.red);
if (Physics.Raycast (transform.position, fwd, hit, 2.00))
{
if(hit.collider.gameObject.tag == ("Electric"))
{
Debug.DrawRay(transform.position, fwd * 2, Color.green);
CanGivePower = true;
}
else if(!hit.collider.gameObject.tag == ("Electric"))
{
CanGivePower = false;
}
}
if(CanGivePower == true)
{
Debug.Log("Yes it is true");
}
else {
Debug.Log("No it is false");
}
}