Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by aled96 · Apr 15, 2014 at 03:08 PM · objectfpschangeweapon

FPS game: weapons

Hi, i am trying to male an FPS game, so i have a character and two weapons, but what should i do to change weapon ?? i need to change one object with another... What does it work ? Someone can explain me this or give me some examples ?? Thank you so much ;)

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by deltamish · Apr 15, 2014 at 03:24 PM

Hi, What you are trying to achieve is really darn simple all you nedd to have is some programming knowledge

Create a new empty gameobject and make your weapos as the child of the new object and attach the script to the object created //Note this script is in JavaScript but since i use lot of C# i amy have made few syntax problems without my knowledge

 public var Weapon:GameObject;
 
 
 
 function Update()
 {
  if(Input.GetKeyDown("1")) // Use keycode.Alpha1 instead used this tome it simpler to understand 
  {
   SetActive(1);
  }
 
 if(Input.GetKeyDown("2")) // If you press 2 then select second object
  {
   SetActive(2);
  }
 
 
 }
 
 function SetActive(WeaponInt:int)
 {
  for(i:int =0; i < transform.childCount;i++) // iterate through this Object's Children  
  {
    if(i == WeaponInt) // if Selected int == current int that is i then Enable the object 
      transform.GetChild(i).gameObject.SetActive(true);
    
     else  // Disable it
    transform.GetChild(i).gameObject.SetActive(false);
     
  }
 }
Comment
Add comment · Show 6 · Share
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 aled96 · Apr 15, 2014 at 03:30 PM 0
Share

There is an error in the code, i am using C#... The errors is on the 25th row : Is not possible to use activeSelf...

avatar image deltamish · Apr 15, 2014 at 03:43 PM 0
Share

hi Sorry about that i dunno why i did that mistaake , this is an javascript one ,are you converting it or using it directly

avatar image Malfegor · Apr 15, 2014 at 03:43 PM 1
Share

Try making it:

 transform.GetChild(i).gameObject.SetActive(true);
avatar image aled96 · Apr 15, 2014 at 03:44 PM 0
Share

Yes yes, i used and it works :D :D thank you so much :)

avatar image Malfegor · Apr 15, 2014 at 06:34 PM 1
Share

Oww sorry, I came across this question and thought I'd comment right away. Anyways, glad it worked!

Show more comments
avatar image
0

Answer by komodor · Apr 15, 2014 at 03:15 PM

you can just hide one and show other by code

or you can play hiding animation and then play showing other animation

Comment
Add comment · Show 1 · Share
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 aled96 · Apr 15, 2014 at 03:16 PM 0
Share

So, i should put every weapons in the right position and then hide the weapons that i am not using ? rigth?

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.

Follow this Question

Answers Answers and Comments

22 People are following this question.

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

Related Questions

How to make a weapon index? 1 Answer

Weapon Shake 2 Answers

Change level after destroying all enemies? 1 Answer

mesh? syntax question. 1 Answer

Any help with a weapon changing script? 2 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