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


#1


#2

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:


#3

Mam still its not spawn desired the position.
position


#4

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.


#5

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.


#6

Thank you. Test the following:

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

#7

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


#8

You’re welcome. :slight_smile:


See also:


automatically bumped #9