- Home /
Third Person Controller
Hi everyone
I'm having problem with Unity Build in Third Person Controller (Assets > 3RD person Controller). I have shooting animations in my character (Empty Hand Animation, and with gun animation), but i don't know how to add Shooting animation in ThirdPersonController.js.
I'm trying to add _characterState = CharacterState.Shooting in Update Function but nothing happens (if(_characterState == CharacterState.Shooting) _animation.CrossFade(shootAnimation.name);
thanks for the answers.
Answer by Griffo · Sep 15, 2012 at 08:47 AM
Hi,
You say that you have shooting animation on the character, so if its called "Shooting" all you have to do is call it when you either press a key or a GUI button on iOS. Something like below, with the script attached to the character that has the animation attached to it.
function Update{
if(Input.GetKeyDown(KeyCode.Space)){ // Call function ShootWeapon when Space is pressed
ShootingWeapon();
}
}
function ShootWeapon(){
animation["Shooting"].layer = 1; // Place the animation on a higher level to override the Walk animation
animation["Shooting"].wrapMode = WrapMode.Once; // Play the animation once all the way through
animation.Play("Shooting"); // Play the animation
}
Thanks a lot. Spent about a day and a half trying to figure this out.
Your answer
Follow this Question
Related Questions
Why does the character controller script default to a loop? 1 Answer
accessing charactercontroller 1 Answer
Mecanim and Child Objects 0 Answers
Animation Returns to previous state after timeline 0 Answers