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;
}
}