- Home /
draw weapon animation
Hello, I want my player to draw a weapon, which i managed. But there's a problem with my booleans when i'm trying to make him draw back his weapon. It's seems the boolean doesn't want to switch. The console is not telling anything, there be somethin wrong with logic ^^. Here's the script
var sword : GameObject;
var weaponOut : boolean = true;
function Update () {
if (Input.GetKeyDown(KeyCode.L)){
Draw();
}
}
function Draw() {
if (!weaponOut) {
animation.Play("drawSword");
weaponOut = true;
yield WaitForSeconds(0.4);
sword.active = true;
}
if (weaponOut) {
animation.Play("drawBackSword");
weaponOut = false;
yield WaitForSeconds(0.4);
sword.active = false;
}
}
Answer by imangomi · Jul 11, 2013 at 04:24 PM
First of all you don't need to use all that code to make weapon swithing, here use this script!! #pragma strict
var Weapon01 : GameObject;
var Weapon02 : GameObject;
function Update () {
if (Input.GetKeyDown(KeyCode.Q))
{
SwapWeapons();
}
}
function SwapWeapons()
{
if (Weapon01.active == true)
{
Weapon01.SetActiveRecursively(false);
Weapon02.SetActiveRecursively(true);
}
else
{
Weapon01.SetActiveRecursively(true);
Weapon02.SetActiveRecursively(false);
}
}
Once you have all that Attach this script to your gun!!
function Update () {
if (Input.GetKeyDown(KeyCode.Q)){
animation.Play("drawSword");
}
Subscribe to me: www.youtube.ca/boubalishgames
Thanks a lot. Even if I wasn't looking for a Weapon Switch Code, only a Weapon Draw Code. By that I meen just make the weapon appear and disappear pressing a key. Either way I found a way to make it work thanks to your script.
Your answer
Follow this Question
Related Questions
dual wielding sword Draw animation help 0 Answers
weapon animation question 1 Answer
Attaching Weapon to Animated Character 0 Answers
Realistic weapon movement with the character 0 Answers
problem with weapon animation -.- 0 Answers