I want to pass desired position of the rock but it is not working?

Hi,

If you need help with your Unity project, please post in the “Ask” sub-forum. I moved your thread for you.

Regarding your issue, add the new keyword in front of Vector3 because you want to create a new Vector3 object.

Did this help?


See also:

Mam still its not spawn desired the position.
position

Please refrain from posting screenshots of your code because it’s impossible to copy and paste lines from them. Instead, insert is as text in your answer and format it. If you do not know how to do that, follow this instruction.

What is the desired position? As it seems, you don’t use the passed on Vector3 object in your LargeAsteroidSpawner method but spawn the prefabs at the same position: transform.position.x and transform.position.y.

void Start()
{
LargeAsteroidSpawner(new Vector3(0,5,0));
LargeAsteroidSpawner(new Vector3(0,-5,0));
LargeAsteroidSpawner(new Vector3(12,0,0));
LargeAsteroidSpawner(new Vector3(-12,0,0));
}

public void LargeAsteroidSpawner(Vector3 position) {
	GameObject rock = Instantiate(prefabAsteroid) as GameObject;
	rock.transform.position = new Vector3(transform.position.x,transform.position.y,0);
}

Please see this code.

Thank you. Test the following:

public void LargeAsteroidSpawner(Vector3 position) {
	GameObject rock = Instantiate(prefabAsteroid) as GameObject;
	rock.transform.position = position;
}

Thank you Mam !!
It worked fine…
:smiley::smiley:

You’re welcome. :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms