- Home /
Spawning platform when i press a button
Hello, im working on a 2D jump 'n run game. One of the Characters is a platform. I want to add the abillity, that when I press on the A button on my gamepad, he spawns a platform on his position, so the other player can jump on that. I want him to spawn 2 platforms, then the first disappears ... I hope you understand.
My code so far:
var speed = 25.0;
function Update () {
var htranslation = Input.GetAxis ("HorizontalP1") speed; var vtranslation = Input.GetAxis("VerticalP1") speed;
htranslation = Time.deltaTime; vtranslation = Time.deltaTime;
transform.Translate (0, 0, htranslation); transform.Translate (0, vtranslation, 0); }
Any ideas? I'm not that grat with js. haha
greetings, T.
Answer by You! · May 26, 2012 at 08:44 PM
One idea (insert within the Update function after everything else):
if (GetButton("/*Insert name of button here!*/"))
private var playerPosition : Vector3 = player.transform.position
Instantiate(platform,playerPosition,Quaternion.identity)
AND insert this before the Update function:
private var player : GameObject //Place the player object from the scene here in the inspector.
var platform : GameObject //Place platform prefab here in the inspector.
I think you should be able to modify this if needed
O$$anonymous$$... Get rid of the "$$anonymous$$ainCharP2.gameObject" and just add it in the inspector... I edit the code to show this.
Your answer

Follow this Question
Related Questions
script dosnt creat object where i want it to 1 Answer
Spawning if there is space 1 Answer
Spawning objects at points within another object? 1 Answer
Spawn object in cube 2 Answers