[Unity 2d]Trying to get a projectile to shoot both ways on the X-axis

In my game, the character shoots an arrow. i used rigidbody2d.velocity.x = (variablehere) to make it move. Thinking it would shoot relatively to my character, the arrow can face the direction it’s shooting, but only goes to the right. Here is my code below:

var projectileSpeed : float = 10;

function Update () {

if(Transform.rotation.y = 180){

rigidbody2D.velocity.x = projectileSpeed*-1;

}else{

rigidbody2D.velocity.x = projectileSpeed;

}

}

I tried making it so if it faces left, it will go left, but I only got an error. Any help would be appreciated, thanks :slight_smile:

As we answered the questions using the comments, here is the full answer of the problem.

You are using “Transform” the component, u should use “transform” the variable associated with the GameObject.

So your if should be:
if(this.gameObject.transform.rotation.y==180)

And like Lo0NuhtiK said, u should “Mathf.Round()” the angle because most of the time the angle will not bet 180 but 180.01, 180.10 and so on.

Gl.