[C#] Help on finding a specific gameobject?

Hello!
So I’m creating a simple multiplayer online game.
When there is a player, it has the actual player and an invisible object called “BulletSpawnPoint” which is a little out from the player so when I shoot a bullet, it will not touch my player to damage to him.
So, this is my current code:

if (Input.GetKeyDown(KeyCode.Q)) {
			if(Time.time > ability1Cooldown){
				ability1Cooldown = Time.time + 5;
				//TODO: Shoots two balls with two players at only one bullet spawn point.
				Rigidbody bulletfire = Network.Instantiate(fireBallProjectile, GameObject.Find("BulletSpawnPoint").transform.position, Quaternion.identity, 0) as Rigidbody;
                bulletfire.AddForce(transform.forward * 350);
			} else {
				audio.PlayOneShot(cancelAudio);
			}
		}

So when I test it with two players online. It will create two fireball object at one spawn point (of player1)
And when player2 tries to press Q, two fireballs at player1’s bulletspawnpoint gets created.
How can I fix this?
I want it to spawn at that object bulletspawnpoint not always player1’s bulletspawnpoint.

Set the player 2 spawnpoint in the inspector by dragging it in. The code with Find you have now is inefficient.
Also, a bullet is a gameObject and the rotation is transform.rotation and not Quaternion.identity.

I’m sorry… that did not help me at all?
Can you or someone else try and explain something in a different way.

I just need a way to make it find the same object that has this script to find that bulletspawnpoint not to search every object for it.

If the spawn points is the child of the player, you can use GetComponentInChildren() and then go through the list (compare if the name is correct) until you find the correct Transform.
Do this in Awake() and store the transform in a class variable.

Ehh so I tried to do this:

public Transform bulletSpawn;

Rigidbody bulletfire = Network.Instantiate(fireBallProjectile, GetComponentInChildren<bulletSpawn>().transform.position, Quaternion.identity, 0) as Rigidbody;

But im getting an error:

Also tried:

Rigidbody bulletfire = Network.Instantiate(fireBallProjectile, this.GetComponentInChildren<bulletSpawn>, Quaternion.identity, 0) as Rigidbody;

but it still didnt work :confused:

you can create custom tags and add them to your objects (like player1bulletspawn/player2bulletspawn) and you can FindGameObjectsWithTag(“”) which gives back a gameobject

I you have a call returning Transform, you get a transform. Your “BulletSpawnPoint” is a name. It goes something like this (untested code):

Transform spawnPoint;
void Awake() {
    Transform[] tmp = GetComponentsInChildren<Transform>();
    foearch(Transform t in tmp) {
        if( t.name == "BulletSpawnPoint" ) {
              spawnPoint = t;
              break;
       }
   }
}

then you can do later:

Rigidbody bulletfire = Network.Instantiate(fireBallProjectile, spawnPoint.position, Quaternion.identity, 0) as Rigidbody;

Great! Now it will only shoot one fireball, but if I have two players online and press Q to shoot it. Both players will shoot the ball. How do I make it so only the player who presses the button, shoots it?

Still need that help :c

Maybe the code in this helps: https://www.assetstore.unity3d.com/#/content/1917

That didnt help at all:/

Can someone please help me with my problem.
I thank you for what you have done lankoski.