- Home /
Using multiple buttons in script
Hi, I have a script called "Actions" that looks like this:
#pragma strict
function Start () {
}
function Update () {
if (Input.GetAxis("Vertical")){
animation.CrossFade("Walk_");
}
else if (Input.GetAxis("Horizontal")){
animation.CrossFade("Walk_");
}
else if (Input.GetButton("Scratch")){
animation.CrossFade("Slash");
}
else if (Input.GetButton("Bite")){
animation.CrossFade("Bite");
}
else if (Input.GetButton("Swat")){
animation.CrossFade("Wing_Swat");
}
else
animation.CrossFade("Rest");
}
I have also added a Third Person Controller Script. I had to put the walk animations and idle animation into my "Actions" script so that the action script wouldn't stop those animations from playing. Now, my question is, how would I add a run animation into my script so that that animation wouldn't be overrode as well?
The Actions Script seems to stop the animations in the Third Person Controller script except for the idle animation. The way I have coped with this is by those same animations into the Actions script. It has worked fine, but with a run animation I would need to be able to press the 'shift' key and the forward key at the same time to run.
How would I script the usage of two keys at once in my actions script for the run animation?
If this is confusing, ask me to explain more clearly.
Thanks!
Answer by ExTheSea · Mar 25, 2013 at 12:23 AM
I don't know if i quite understood your problem but does this work for you:
function Update () {
...
else if (Input.GetAxis("Vertical")){
if(Input.GetAxis("Vertical")>0 && Input.GetButton("Run")){
animation.CrossFade("Run_");
}else
animation.CrossFade("Walk_");
}
....
Btw. If your problem is solved accept and answer or close the question if not please provide more information.
Answer by goldkillerv · Mar 25, 2013 at 10:17 PM
Why are the buttons named, Bite and Scratch? You probably need to provide us with more information.
The Bite and scratch thing i guess are just input configuration he did in the input settings. I think bite and scratch aren't even really relevant for this question
Ik that he will be able to sprint both ways... It depends on him whether or not he wants to do it or not. He can easily remove it if he doesn't require it. And btw, that's with the holding down shift too which is probably what he wants.
Yes right. I'm a bit curious why gamezdragon didn't accepted a question or even just posted a comment if something isn't working or doesn'T fulfill his needs.
Answer by goldkillerv · Mar 25, 2013 at 10:36 PM
Ok. I think you should try this:
function Update() {
if (Input.GetButtonDown("Sprint") && (Input.GetButtonDown("Vertical") || Input.GetButtonDown("Horizontal"))) {
animation.CrossFade("Run_");
}
}
The Problem with your script is that this way the player will be able to sprint even when walking backwards and sideways. ($$anonymous$$y answer should work for the question. just saying)
Your answer
Follow this Question
Related Questions
play animation when moving,and idle animation when stand still 1 Answer
scripting Animations 1 Answer
Enemy Animation Freezing in first frame 2 Answers
Animay play in editor 0 Answers
how to get a animation from other script on colision 1 Answer