Search Unity

Character Switch, help

Discussion in 'Getting Started' started by MatD1, Jun 27, 2020.

  1. MatD1

    MatD1

    Joined:
    May 25, 2020
    Posts:
    1
    Hi guys I recently started a new project with the aim to learn some new things I relatively new so I don't know a lot about C sharp. I created a script from the help of a video to create a button that should change what character is active. but because these characters have a gun system involved every time I go to click the button on the UI it shoots instead, Is there a way around this? any help would be much appreciated guys, screenshots and code will be below!

    -code-
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Seletion : MonoBehaviour
    {
    public GameObject Handgun_01_FPSController, Assault_Rifle_01_FPSController;

    int whichAvatarIsOn = 1;

    private void Start()
    {
    Handgun_01_FPSController.gameObject.SetActive(true);
    Assault_Rifle_01_FPSController.gameObject.SetActive(false);
    }

    public void SwitchAvatar()
    {
    switch (whichAvatarIsOn)
    {
    case 1:

    whichAvatarIsOn = 2;

    Handgun_01_FPSController.gameObject.SetActive(false);
    Assault_Rifle_01_FPSController.gameObject.SetActive(true);
    break;

    case 2:

    whichAvatarIsOn = 1;
    Handgun_01_FPSController.gameObject.SetActive(true);
    Assault_Rifle_01_FPSController.gameObject.SetActive(false);
    break;
    }
    }
    }
    Game Screenshot
    https://pasteboard.co/JeZcx00.png
    Hierarchy
    https://pasteboard.co/JeZcSYs.png