- Home /
Question by
xxxmrfunxxx · Jun 25, 2013 at 05:58 PM ·
transformpositionspawningnewbie
How can I grab the position of an object, use it for the instance of a prefab and change the y position of it?
I'm making the effect of a power up. It's supposed to take the position of a spawn point that is currently placed in the scene and give that same position but with a modified y-value to the prefab. The Problem:
What it currently does is instantiate the prefab in the spawns exact position. I want it to be a little higher.
CODE:
public void Effect(){
//Activates the flag of the effect
PowUp_effect = true;
Transform spawn = GameObject.Find ("SpawnPoint" + Random.Range (0,8)).transform;
//Searches for the prefab in the assets
Object prefab = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Object.prefab", typeof(GameObject));
//Creates the instance with the coordinates
GameObject prefab_clone = (GameObject)Instantiate(prefab,spawn.position,spawn.rotation);
}
Please help!
Comment
Best Answer
Answer by fafase · Jun 25, 2013 at 06:00 PM
You need to store the value first and modify it.
Transform spawn = GameObject.Find ("SpawnPoint" + Random.Range (0,8)).transform;
Vector3 vec = spawn.position;
vec.y += 0.5f; // little higher
GameObject prefab_clone = (GameObject)Instantiate(prefab,spawn.position,spawn.rotation);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Transform.position without Vector3? 1 Answer
platforme ...HELP!! POSITION ADDING 1 Answer