Right now i have a bullet script which is ingerited from by 3 other kinds of bullets. In this prant bullet script, I have it read from a bool in the player’s script which direction the player is facing to base the bullet’s direction off of.
Now that i have to create an enemy script that is able to shoot the same bullets, i have come across my problem; the Bullet script uses
GameObject thePlayer = GameObject.Find("Player");
PlayerController PlayerScript = thePlayer.GetComponent<PlayerController>();
if(!PlayerScript.facingRight)
{
speed = speed*-1;
}
So if an enemy wants to fire, i’d have to write an identical copy of this script and its children and substitute PlayerController with EnemyController if i want it to work the same way.
The Shoot() method in the PlayerController script instantiates a bullet at the player’s position, then checks the player’s direction specifically and moves that way.
in short, the bullet GameObject, which has its own script checks the player’s direction itself when executing Start().
How i understand this code is that as soon as the bullet is spawned, it looks around the world for the player’s facing direction, then moves in that direction.
what i want to change it into is that as soon as the bullet is spawned, it asks “who shot me?” and then looks for the facing direction of the prefabbed instance that shot the bullet.
the “Who shot me?” is the essence of my problem, really.
So what i’d like to know: Is there a way to accomplish this by saying “just get facingRight from whoever shot you, nevermind who that is” ?
Because that would really make my day.
i could provide you the script if needed.
Edit: fixed poor wording and added more info.