• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by DutchWarfare12 · May 16, 2012 at 01:25 PM · weaponswitchingpersonthird

Weapon Switching 3th Person

hi i got a question i got an 3th person character ant i want to weaponswitch whit animation

my guns are attatched to my right hand

the problem i got is that i can switch whit animation but as soon as i press 2 my hands already go in the positon from my pistol(second gun)

i tried to set a timer on it but it didend work

does someone of you now my awnser

thanks.

Edited : Code moved from comments to original post.

 var Player : GameObject;
 var AnimScript1 = "";
 var AnimScript2 = "";
 var PrimarySlot : GameObject;
 var SecondarySlot : GameObject;
 //private var UMP45 : boolean = false;
 //private var M9 : boolean = false;
 private var PrimarySelected : boolean = false;
 private var SecondarySelected : boolean = false;
  
 function Start () {
    Player.GetComponent(AnimScript1).enabled = true;
    Player.GetComponent(AnimScript2).enabled = false;
    PrimarySelected = true; SecondarySelected = false;
    PrimarySlot.gameObject.SetActiveRecursively(true);
    SecondarySlot.gameObject.SetActiveRecursively(false);
    animation["switch-down"].layer = 30;
    animation["switch-up"].layer = 30;
    animation["switch-down-ump3"].layer = 30;
    animation["switch-up-ump2"].layer = 30;
 }
  
 function Update () {
    if (Input.GetKey("1")) {
       if (SecondarySelected) {
          Player.animation.CrossFade("switch-down");
          W1();
       }
    }
    else if (Input.GetKey("2")) {
       if (PrimarySelected) {
          Player.animation.CrossFade("switch-up");
          W2();
       }
    }
 }
  
 function W1 (){
    animation.Stop();
    //Player.animation.Play("switch-down");
    //PrimarySlot.gameObject.SetActiveRecursively(false);
    //SecondarySlot.gameObject.SetActiveRecursively(true);
    yield WaitForSeconds(0.4);
    animation.Stop("switch-down");
    Player.animation.CrossFade("switch-up-ump2");
    PrimarySlot.gameObject.SetActiveRecursively(true);
    SecondarySlot.gameObject.SetActiveRecursively(false);
    Player.GetComponent(AnimScript1).enabled = true;
    Player.GetComponent(AnimScript2).enabled = false;
    PrimarySelected = true;
    SecondarySelected = false;
 }
  
 function W2 (){
    animation.Stop();
    Player.animation.CrossFade("switch-up");
    //PrimarySlot.gameObject.SetActiveRecursively(true);
    //SecondarySlot.gameObject.SetActiveRecursively(false);
    yield WaitForSeconds(0.4);
    Player.animation.Stop("switch-up");
    PrimarySlot.gameObject.SetActiveRecursively(false);
    SecondarySlot.gameObject.SetActiveRecursively(true);
    Player.GetComponent(AnimScript1).enabled = false;
    Player.GetComponent(AnimScript2).enabled = true;
    PrimarySelected = false;
    SecondarySelected = true;
 }
Comment

People who like this

0 Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Berenger · May 16, 2012 at 03:49 PM 0
Share

Could you post a bit of code ?

avatar image DutchWarfare12 · May 21, 2012 at 08:01 AM 0
Share

ok but its realy messy

avatar image DutchWarfare12 · May 21, 2012 at 08:02 AM 0
Share

this is what i got so far

var Player : GameObject; var AnimScript1 = ""; var AnimScript2 = ""; var PrimarySlot : GameObject; var SecondarySlot : GameObject;

//private var UMP45 : boolean = false; //private var M9 : boolean = false; private var PrimarySelected : boolean = false; private var SecondarySelected : boolean = false;

function Start () { Player.GetComponent(AnimScript1).enabled = true; Player.GetComponent(AnimScript2).enabled = false;

PrimarySelected = true; SecondarySelected = false;

PrimarySlot.gameObject.SetActiveRecursively(true); SecondarySlot.gameObject.SetActiveRecursively(false);

 animation["switch-down"].layer = 30;
 animation["switch-up"].layer = 30;
  animation["switch-down-ump3"].layer = 30;
   animation["switch-up-ump2"].layer = 30;

}

function Update () { if (Input.GetKey("1")) { if (SecondarySelected) { Player.animation.CrossFade("switch-down"); W1();

} } else if (Input.GetKey("2")) { if (PrimarySelected) { Player.animation.CrossFade("switch-up"); W2();

} } }

function W1 (){ animation.Stop(); //Player.animation.Play("switch-down"); //PrimarySlot.gameObject.SetActiveRecursively(false); //SecondarySlot.gameObject.SetActiveRecursively(true); yield WaitForSeconds(0.4); animation.Stop("switch-down"); Player.animation.CrossFade("switch-up-ump2"); PrimarySlot.gameObject.SetActiveRecursively(true); SecondarySlot.gameObject.SetActiveRecursively(false); Player.GetComponent(AnimScript1).enabled = true; Player.GetComponent(AnimScript2).enabled = false; PrimarySelected = true; SecondarySelected = false; }

function W2 (){ animation.Stop(); Player.animation.CrossFade("switch-up"); //PrimarySlot.gameObject.SetActiveRecursively(true); //SecondarySlot.gameObject.SetActiveRecursively(false); yield WaitForSeconds(0.4); Player.animation.Stop("switch-up"); PrimarySlot.gameObject.SetActiveRecursively(false); SecondarySlot.gameObject.SetActiveRecursively(true); Player.GetComponent(AnimScript1).enabled = false; Player.GetComponent(AnimScript2).enabled = true; PrimarySelected = false; SecondarySelected = true; }

avatar image syclamoth · May 21, 2012 at 08:56 AM 0
Share

Could you edit that to be a bit better formatted? All you need to do is put four spaces before each line.

avatar image Lo0NuhtiK · May 22, 2012 at 02:48 AM 0
Share

@DutchWarfare12 : Just stumbled upon this thread. Edited your main post and added your code to it for you since this is your first topic/post on the site. Try formatting properly next time.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Third Person Shooter 2 Answers

Third person camera 0 Answers

How to add a third Variable? 2 Answers

ThirdPerson Unity Networking? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges