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 /
  • Help Room /
avatar image
0
Question by craftydeadman111 · Sep 21, 2020 at 10:04 PM · weaponsweaponchanging

i need help with weapon pick ups c#,need help with weapon changing script and weapon pick up script

when i only have this bit of code it works if (floorAk47Active == true && m4a1Active == true) { m4a1.SetActive(false); m4a1Active = false; smgActive = false; smg.SetActive(false); ak47Active = true; ak47.SetActive(true); //sets the floor weapon floorAk47Active = false; floorm4a1Active = true;

         }
         if(floorAk47Active == true && smgActive ==true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = true;
             ak47.SetActive(true);
             //sets the floor weapon
             floorAk47Active = false;
             floorSmgActive = true;
             
         }

but when i use the following it doesn't work if(floorAk47Active == true && m4a1Active == true) { m4a1.SetActive(false); m4a1Active = false; smgActive = false; smg.SetActive(false); ak47Active = true; ak47.SetActive(true); //sets the floor weapon floorAk47Active = false; floorm4a1Active = true;

         }
         if(floorAk47Active == true && smgActive ==true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = true;
             ak47.SetActive(true);
             //sets the floor weapon
             floorAk47Active = false;
             floorSmgActive = true;
             
         }
         if(floorm4a1Active == true && ak47Active == true)
         {
             m4a1.SetActive(true);
             m4a1Active = true;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = false;
             ak47.SetActive(false);
             //sets the floor weapon
             floorm4a1Active = false;
             floorAk47Active = true;
             
         }
         if (floorm4a1Active == true && smgActive == true)
         {
             m4a1.SetActive(true);
             m4a1Active = true;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = false;
             ak47.SetActive(false);
             //sets the floor weapon
             floorm4a1Active = false;
             floorSmgActive = true;
         }
         if(floorSmgActive == true && ak47Active == true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = true;
             smg.SetActive(true);
             ak47Active = false;
             ak47.SetActive(false);
             //sets the floor weapon
             floorSmgActive = false;
             floorAk47Active = true;
         }
         if (floorSmgActive == true && m4a1Active == true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = true;
             smg.SetActive(true);
             ak47Active = false;
             ak47.SetActive(false);
             //sets the floor weapon
             floorSmgActive = false;
             floorm4a1Active = true;
         },my weapon switching works fine but when i try and pick up a weapon of the floor it wont pick up. but if i only have this it works

if(floorAk47Active == true && m4a1Active == true) { m4a1.SetActive(false); m4a1Active = false; smgActive = false; smg.SetActive(false); ak47Active = true; ak47.SetActive(true); //sets the floor weapon floorAk47Active = false; floorm4a1Active = true;

         }
         if(floorAk47Active == true && smgActive ==true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = true;
             ak47.SetActive(true);
             //sets the floor weapon
             floorAk47Active = false;
             floorSmgActive = true;
             
         }





using System.Collections; using System.Collections.Generic; using UnityEngine;

public class gunController : MonoBehaviour { //player public float distanceToPlayer; public Transform player; //smg public GameObject smg; public bool smgActive = false; //m4a1 public GameObject m4a1; public bool m4a1Active = false; //ak47 public GameObject ak47; public bool ak47Active = false; //floor gun public float rangeToFloorGun; public bool inRangeTofloorGun; public Transform floorGunPosition; public float distanceTofloorGun; //gun on the floor public GameObject floorAk47; public bool floorAk47Active = false; public GameObject floorSmg; public bool floorSmgActive = false; public GameObject floorm4a1; public bool floorm4a1Active = false;

 // Start is called before the first frame update
 void Start()
 {
     //active = true;
     floorAk47Active = true;
     floorSmgActive = false;
     floorm4a1Active = false;
     m4a1Active = false;
     m4a1.SetActive(false);
     ak47Active = false;
     ak47.SetActive(false);
     player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
     floorGunPosition = GameObject.FindGameObjectWithTag("floorGun").GetComponent<Transform>();

     rangeToFloorGun = 5f;

 }

 // Update is called once per frame
 void Update()
 {
     distanceToPlayer = Vector3.Distance(player.position, transform.position);
     distanceTofloorGun = Vector3.Distance(floorGunPosition.position, transform.position);

     //my attempt at picking up a gun

     if (distanceTofloorGun < rangeToFloorGun && Input.GetButtonDown("e"))
     {
         
         if(floorAk47Active == true && m4a1Active == true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = true;
             ak47.SetActive(true);
             //sets the floor weapon
             floorAk47Active = false;
             floorm4a1Active = true;
             
         }
         if(floorAk47Active == true && smgActive ==true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = true;
             ak47.SetActive(true);
             //sets the floor weapon
             floorAk47Active = false;
             floorSmgActive = true;
             
         }
         if(floorm4a1Active == true && ak47Active == true)
         {
             m4a1.SetActive(true);
             m4a1Active = true;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = false;
             ak47.SetActive(false);
             //sets the floor weapon
             floorm4a1Active = false;
             floorAk47Active = true;
             
         }
         if (floorm4a1Active == true && smgActive == true)
         {
             m4a1.SetActive(true);
             m4a1Active = true;
             smgActive = false;
             smg.SetActive(false);
             ak47Active = false;
             ak47.SetActive(false);
             //sets the floor weapon
             floorm4a1Active = false;
             floorSmgActive = true;
         }
         if(floorSmgActive == true && ak47Active == true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = true;
             smg.SetActive(true);
             ak47Active = false;
             ak47.SetActive(false);
             //sets the floor weapon
             floorSmgActive = false;
             floorAk47Active = true;
         }
         if (floorSmgActive == true && m4a1Active == true)
         {
             m4a1.SetActive(false);
             m4a1Active = false;
             smgActive = true;
             smg.SetActive(true);
             ak47Active = false;
             ak47.SetActive(false);
             //sets the floor weapon
             floorSmgActive = false;
             floorm4a1Active = true;
         }
     }


    
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

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.

Follow this Question

Answers Answers and Comments

207 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pickup weapons in 2D scroller game 1 Answer

Switching items - can't detect a crazy loop that is happening. 1 Answer

Storing diffrent bullet amounts for different Weapons. 1 Answer

How to properly design weapons with evolutions (as rachet & clank weapons) 2 Answers

Weapon Select Menu 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