Hi everyone,
I know many many many people have asked this, but none of the answers really relate to my code (I don’t think so anyways) so I have to ask again…
So, my issue is that my player can shoot a bullet (the projectile prefab) but, it only shoots to the right and I don’t know how to change it to make it go left and right… yes, I am a complete noob at this.
But here is my code:
(This is the ProjectilePrefab script):
public float speed = 10.0f;
private GameManager gameManager;
// Start is called before the first frame update
void Start()
{
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
}
// Update is called once per frame
void Update()
{
// Makes the projectile move to the right at the set speed.
// Yea, I feel like this need to be changed to not be directed to the right lol
transform.Translate(speed * Time.deltaTime * Vector2.right);
}
(and this is the PlayerMovement script):
// Shooting bullets
if (Input.GetKeyDown(KeyCode.Space))
{ // Instantiate makes the projectile spawn at the player's position.
Instantiate(projectilePrefab, new Vector3(transform.position.x + 1, transform.position.y), projectilePrefab.transform.rotation);
}
I really hope someone can help me, thank you guys so muchh!!!