Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Jan 13 at 09:49 PM by Wesley21spelde for the following reason:

fixed it my self

avatar image
0
Question by Wesley21spelde · Jan 13 at 08:14 PM · intweaponswitchother scriptby

Change Weapon by its Script int

hey guys i wanted to ask how i can Set a Weapon on in this script by setting the selectWeapon int to a 1or 2 or 3 i tried getting this ....

 if (selectWeapon >= transform.childCount - 1)
                 selectWeapon = 0;
             
             else
                 selectWeapon++;

in to my

 public void Weapon_1_Selected(){
 }

this is for my savegame manager. all the parts work this script shares its selected weapon int to my loadSave Script and i can load it back in to the selecweapon int works fine but i cant get it woking that it will go to weapon 0 if the selectweapon int is 0. i even tried this

 void Selectweapon()

{

} here is the script...

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class WeaponSwitchMouseWheel : MonoBehaviour
 {
     public Animator anim;
     public GameObject[] Weapons;
     public GameObject Player;
  
     public GameObject CurrentWeapon;
  
     public int selectWeapon = 0;
 
     public bool isWeapon_1 = false;
     public bool isWeapon_2 = false;
     public bool isWeapon_3 = false;
 
     void Start()
     {
          //anim = GetComponentInChildren<Animator>();
         Selectweapon();
         Player = GameObject.FindGameObjectWithTag("Player");
         Player.SendMessage("Weapon_1True");
         Debug.Log("selected weapon = 0 ");
 
     }
     public void Weapon_1_Selected()
     {
         if(isWeapon_1 == true)
         {
             // do nothing
         }
         else
         {
             isWeapon_1 = true;
             isWeapon_2 = false;
             isWeapon_3 = false;
 
                 selectWeapon = 0;
         }
 
         
     }
     public void Weapon_2_Selected()
     {
         if(isWeapon_2 == true)
         {
             // Do nothing
         }
         else
         {
             isWeapon_1 = false;
             isWeapon_2 = true;
             isWeapon_3 = false;
             
                 selectWeapon = 1;
         }
         
     }
     void Update()
     {
         
         int previousSelectedWeapon = selectWeapon;
 
         if (Input.GetAxis("Mouse ScrollWheel") > 0f)
         {
             CurrentWeapon.GetComponent<Animator>().enabled = false;
             anim.SetBool("WeaponSwitcherAnim", true);
             anim.SetBool("WeaponSwitcherAnimIlde", false); 
             if (selectWeapon >= transform.childCount - 1)
                 selectWeapon = 0;
             
             else
                 selectWeapon++;
            // Weapon_1_Selected();
         }
 
         if (Input.GetAxis("Mouse ScrollWheel") < 0f)
         {
             CurrentWeapon.GetComponent<Animator>().enabled = false;
             anim.SetBool("WeaponSwitcherAnim", true);
             anim.SetBool("WeaponSwitcherAnimIlde", false);
             if (selectWeapon <= 0)
                 selectWeapon = transform.childCount -1;
             else
                 selectWeapon--;
             //Weapon_2_Selected();
         }
         if (previousSelectedWeapon != selectWeapon)
         {
             StartCoroutine(WaitForAnimationTime());
             CurrentWeapon.GetComponent<Animator>().enabled = true;
         }
         if(selectWeapon == 0)
         {
             Player = GameObject.FindGameObjectWithTag("Player");
             Player.SendMessage("Weapon_1True");
             isWeapon_1 = true;
             isWeapon_2 = false;
             isWeapon_3 = false;
             
                
 
 
         }
         if (selectWeapon == 1)
         {
             Player = GameObject.FindGameObjectWithTag("Player");
             Player.SendMessage("Weapon_2True");
             isWeapon_1 = false;
             isWeapon_2 = true;
             isWeapon_3 = false;
             
                
 
         }
 
     }
     IEnumerator WaitForAnimationTime()
     {
         
         
         yield return new WaitForSeconds(0.75f);
         Selectweapon();
         anim.SetBool("WeaponSwitcherAnim", false);
         anim.SetBool("WeaponSwitcherAnimIlde", true);
         
     }
     void Selectweapon()
     {
         int i = 0;
         foreach (Transform weapon in transform)
         {
             if (i == selectWeapon)
                 weapon.gameObject.SetActive(true);
             else
                 weapon.gameObject.SetActive(false);
             i++;
         }
     }
 
 }







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

  • Sort: 

Follow this Question

Answers Answers and Comments

133 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

Related Questions

Weapon pick up and switching script 2 Answers

Weapon Switching 1 Answer

FPS Switching Weapons on iPhone 1 Answer

Why doesn't this weapon switching script work 1 Answer

best way to weapon swapping 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