- Home /
Help on a Power-Up Sequence
What I am attempting to do is to place a 3D model of a helium tank in the air, and when the player touches it, it disappears, a cloud of smoke pops up in front of the player, and when the smoke disappears, the player has changed colour and can jump higher than before.
I'm only quite novice at scripting, and all I have been able to accomplish is to get the helium tank stay in the air, and when the player touches it, it disappears. I have been trying in vain to get the rest to work though, but I don't know what to look for.
My character's jumping value is in another script that is attached to the player. I was thinking of using two functions in the one script to use one action after the other, but I could not get it to work.
What I'm looking for is how to activate these actions properly in order. I think I know what to do for the cloud of smoke (just a particle system that appears for a second...?), but I don't know how to script it in.
Hope you guys can help! :D
Answer by Heratitan · Sep 23, 2010 at 02:33 AM
The easiest way I could see doing this is having a script on the helium tank so when the player touches it it starts of a everything.
For the particle system you would probably have a particle system attached to the helium tank and activate it for a few seconds the deactivate it like this:
var cloudOfSmoke : GameObject;
function OnTriggerEnter(c : Collider) { cloudOfSmoke.SetActiveRecursively = true; }
Then for the color you would just change the color of the material that is on the player, so:
var thePlayer : GameObject;
thePlayer.renderer.material.color = Color.red;
then last for the jumping higher you would tell the jumping script to execute a function that increases the variable to what you want, so:
var thePlayer : GameObject;
var pl : InsertScriptWithJumpingHere = thePlayer.GetComponent(InsertScriptWithJumpingHere); pl.RaiseJumpAmount();
This would be the receiving function inside of the script with the jumping variable:
function RaiseJumpAmount(){
jumpvariable = 5;
}
Hope that helps.
(Edit)
Ok, so for the new version I just combined it into one script.
This is the main script attached to the helium tank, you will have to put the name of the movement script you are using where I put MyFPSWalker.
var cloudOfSmoke : GameObject; var thePlayer : GameObject; var thePlayerGraphic : GameObject;
function OnTriggerEnter(c : Collider) { var pl : MyFPSWalker = thePlayer.GetComponent( MyFPSWalker );
cloudOfSmoke.SetActiveRecursively(true);
thePlayerGraphic.renderer.material.color = Color.red;
pl.RaiseJumpAmount();
yield WaitForSeconds(3);
cloudOfSmoke.SetActiveRecursively(false);
yield WaitForSeconds(10);
thePlayerGraphic.renderer.material.color = Color.green;
pl.ResetJump();
}
And these functions should be added to the end of your movement script:
function RaiseJumpAmount(){
jumpspeed = 16.0;
gravity = 10.0;
}
function ResetJump(){
jumpspeed = 8.0;
gravity = 20.0;
}
Depending on what your gravity and jumpspeed are, you want to raise the jumpspeed and cut the gravity in half. Then in ResetJump they should return to normal.
Feel Free to ask, if you have anymore questions.
I'm not that great at scripting, and following your guide, I cannot seem to get it to work. I seem to be activating the smoke whenever I hit the space bar, my character will not change colour, and the script will not change. Also, I cannot seem to set any variables outside the script in the inspector. Why is that?
I'm not sure, but I will do some testing and see what the problems might be.
That should work, I added something to reset it after a certain amount of time, like a power-up, you can take that out if you want, just take out:
yield WaitForSeconds(10);
thePlayerGraphic.renderer.material.color = Color.green;
pl.ResetJump();
Your answer
Follow this Question
Related Questions
How to get a value from an array within another script. 1 Answer
When passing a value it becomes null 0 Answers
Script for blowing to a particle system 0 Answers
change bar position 1 Answer
How do i disable a script from a different script? 5 Answers