instantiate спавнит 2 клона
пытаюсь создать механизм переключения оружия в игре но почему-то когда я нажимаю E в руке появляются вместо одной пушки 2
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class wearonSwitch : MonoBehaviour
{
public GameObject Gun
public GameObject Ruka;
public GameObject ruka1;
private void OnTriggerStay2D(Collider2D other)
{
if (other.CompareTag("gun") || (other.CompareTag("agun")))
{
if (Input.GetKeyDown(KeyCode.E))
{
if (Gun.activeInHierarchy == true)
{
Destroy(Gun);
other.gameObject.tag = "agun";
Instantiate(other.gameObject, Ruka.transform.position, Quaternion.identity, ruka1.transform);
Destroy(other.gameObject);
}
Gun = GameObject.FindGameObjectWithTag("agun");
Gun.GetComponent<gun>().enabled = true;
}
}
}
}