Im referencing a boolean called ray from other script on the same GameObject called Player.js. Its a codition, so Im using - if (Imput.GetButton(“Laser”) && GetComponent(Player).ray) . It works, but also give me null reference exeptions for some reason. I already used it on other scripts with no problems. What am i doing wrong?
function Update () {
if (Input.GetButton("Laser") && GetComponent(Player).ray)
{
var hit0 : RaycastHit;
var hit1 : RaycastHit;
var hit2 : RaycastHit;
if (GetComponent(Player).multiplier == 0)
{
if (Physics.Raycast(Vector3(transform.position.x,transform.position.y,transform.position.z + 1), Vector3.forward,hit0,100))
{
Instantiate (alienHit,hit0.transform.position,hit0.transform.rotation);
DefineHitString(hit0.transform.tag);
}
}
else if (GetComponent(Player).multiplier == 1)
{
if (Physics.Raycast(transform.position, Vector3.forward,hit0,100))
{
Instantiate (alienHit,hit0.transform.position,hit0.transform.rotation);
DefineHitString(hit0.transform.tag);
}
if (Physics.Raycast(transform.position, Vector3.forward,hit1,100))
{
Instantiate (alienHit,hit1.transform.position,hit1.transform.rotation);
DefineHitString(hit1.transform.tag);
}
if (Physics.Raycast(transform.position, Vector3.forward,hit2,100))
{
Instantiate (alienHit,hit2.transform.position,hit2.transform.rotation);
DefineHitString(hit2.transform.tag);
}
}
}
}