Hi guys i am currently using two scripts to choose my weapon before I spawn my player into the game and use two models.(knife and gun)But when i choose my gun, my (knife model) spawns too.Same the other way too.I have no idea why this happens.Here’s my script.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class WeaponManager : MonoBehaviour {
public List<Gun> Weapons = new List<Gun>();
public int CurWeapon;
public static WeaponManager Instance;
// Use this for initialization
void Start () {
Instance = this;
}
// Update is called once per frame
void Update () {
CurWeapon = GUIManager.Instance.CurWeapon;
}
public void Spawn()
{
CurWeapon = GUIManager.Instance.CurWeapon;
transform.root.GetComponent<Character> ().Server_GetGun (Weapons [CurWeapon].Name);
ApplyWeapon();
}
public void ApplyWeapon()
{
foreach (Gun gu in Weapons)
{
if(gu == Weapons[CurWeapon])
{
gu.gameObject.SetActive(true);
}
else
{
gu.gameObject.SetActive(false);
}
}
}
public static Gun FindWeapon(string Name)
{
foreach (Gun Gu in Instance.Weapons)
{
if(Name == Gu.Name)
return Gu;
}
return null;
}
}
The other one:(near Client_GetGun)
[RPC]
public void Client_GetGun(string name)
{
foreach (ThirdPersonGuns tpg in Guns)
{
if(tpg.Name == name)
{
tpg.Obj.SetActive(true);
Debug.Log (tpg + "Done");
}
else
{
tpg.Obj.SetActive (false);
Debug.Log (tpg + "Not Done");
}
}
}
[System.Serializable]
public class ThirdPersonGuns
{
public string Name;
public GameObject Obj;
}
}