If player faces right, shoot right. viceversa?

I made a script that tells unity when my player faces right or doesn’t.

var isRight : boolean = true;

function update(){

if(Input.GetKey(“a”)){ //Player moves left
AT.rowNumber = 1;
isRight = false;
} else if(Input.GetKey(“d”)){
AT.rowNumber = 1;
isRight = true;

}

Unfortunately my projectile script (the speed and direction the projectile goes) is in another script. How do I reference the player script so that I can say in the projectile script

"if(isRight == true){

transform.Translate(Vector3(-speed * Time.deltaTime, 0, 0));
Destroy(gameObject, 1);

}

and

if(isRight = “false”{
transform.Translate(Vector3(speed * Time.deltaTime, 0, 0));
Destroy(gameObject, 1);
}

something like that? How do I go about this? total noob here so any suggestions and help is greatly appreciated!

You need to clean up the formatting as most of your code isn’t in code format, making it hard to read.

If I understood correctly all you want is to be able to reference the isRight variable from your player script in your projectile script. Include the below in your projectile script, and substitute “Player” for your player gameobject’s name and PlayerScript for the name of the script on the player gameobject that isRight is in.

var player : PlayerScript;

function Start() {
    player = GameObject.Find("Player").GetComponent(PlayerScript);
}

Then when you need to use it you can do it like this

if(player.isRight == true){
    transform.Translate(Vector3(-speed * Time.deltaTime, 0, 0));
    Destroy(gameObject, 1);
}

Another tip is that for booleans you don’t have to write out the true/false comparisons.

“if(player.isRight)” instead of “if(player.isRight == true)”

“if(!player.isRight)” instead of “if(player.isRight == false)”