Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Weapon Change Problem

Discussion in 'Scripting' started by UMURAS, Mar 16, 2020.

  1. UMURAS

    UMURAS

    Joined:
    Jun 15, 2019
    Posts:
    18
    How can I switch between the two guns with the space key, but now I can switch from gun 1 to gun 2, and I cannot switch from gun 2 to gun 1.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Given how much code you posted above, the short answer is "disable weapon 1 and enable weapon 2."
     
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    I can switch between guns 1 and 3 with an enter key. and from the last gun to the previous gun with a backspace. how can I switch to gun 4 if I can skip a gun with an 'M' key?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Again, given how much relevant code you have shared, the answer is "skip one in your list."
     
  5. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Sry, it's not the same person. I was trying to be funny about the apparent disability on the OP's part to phrase a reasonable question. It did sound similar even though I tried my best to make it obviously funny.
     
  6. UMURAS

    UMURAS

    Joined:
    Jun 15, 2019
    Posts:
    18
    Code here please help me

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

    public class SilahDegistirme : MonoBehaviour
    {
    public string[] silahEnv;
    public GameObject[] silahListe;
    public int suankiSilah;
    public bool Silah1, Silah2;
    void Start()
    {
    suankiSilah = 0;
    SilahDegistir(silahEnv[suankiSilah]);
    Debug.Log("AK47 Secildi");
    }


    void Update()
    {
    if (Input.GetKeyDown(KeyCode.Space) && suankiSilah != 0 && silahEnv[0] != string.Empty)
    {
    SilahDegistir(silahEnv[0]);
    suankiSilah = 0;
    Debug.Log("AK47 Secildi");

    }

    if (Input.GetKeyDown(KeyCode.Space) && suankiSilah != 1 && silahEnv[1] != string.Empty)
    {
    SilahDegistir(silahEnv[1]);
    suankiSilah = 1;
    Debug.Log("Desert Eagle Secildi");

    }


    }

    public void SilahDegistir(string silahismi)
    {
    for(int i = 0; i < silahListe.Length; i++)
    {
    if(silahListe.name == silahismi)
    {
    silahListe.gameObject.SetActive(true);
    }
    else
    {
    silahListe.gameObject.SetActive(false);
    }
    }
    }
    }