I’m writing a simple script for my FPS exercise so my character draws his weapon by clicking the right mouse button, and then puts it away with another click of the right mouse button. I have the first part working, but haven’t managed to get the character to put away the weapon again.
The Javascript code I’m using is very simple, and linked to an animator.
#pragma strict
var Gun : GameObject;
var GunDrawn = false;
function Start () {}
function Update () {
if(GunDrawn && Input.GetMouseButtonDown(1)) {
Gun.GetComponent(Animator).SetBool("GunOut", false);
Gun.GetComponent(AudioSource).enabled = false;
GunDrawn = false;
}
if(!GunDrawn && Input.GetMouseButtonDown(1)){
Gun.GetComponent(Animator).SetBool("GunOut", true);
Gun.GetComponent(AudioSource).enabled = true;
GunDrawn = true;
}
}
When I run the game and right-click the correct animation plays and I can see the inspector marks the variable GunDrawn as “true”, but when I right-click again nothing happens. Is this an issue with formatting? I’m sure there’s a simple explanation and any help would be much appreciated.
Thanks!
Thank you very much - that worked well.
– cargo1983You're welcome. :) If you are satisfied with the answer, please mark it as accepted, so people browsing the question queue can visually see that you don't need help with this topic anymore. :)
– Phantomized