Question by
tomfoxba · Oct 07, 2019 at 09:11 PM ·
gameobjectweapon
Put all info from one game object to another one
I'm trying to develop some kind of weapon system without a inventory (for now - pick up item system). So when user onTrigger and press "F", than I change a weapon. But I must pass all params one by one. Can I just change one game object to another without changing all params by myself?
public class GroundObjectType : MonoBehaviour {
public string type;
public string id;
public PlayerController player;
public GameObject playerGun;
public GameObject groundWeaponObject;
private bool isTriggered = false;
// Start is called before the first frame update
void Start() {
}
// Update is called once per frame
void Update() {
if (isTriggered) {
if (Input.GetKeyDown(KeyCode.F)) {
print("F Pressed");
GunController currentGunController = playerGun.GetComponent<GunController>();
MeshFilter currentGunMesh = playerGun.GetComponent<MeshFilter>();
BoxCollider currentGunCollider = playerGun.GetComponent<BoxCollider>();
MeshRenderer currentGunMeshRender = playerGun.GetComponent<MeshRenderer>();
GunController groundGunController = groundWeaponObject.GetComponent<GunController>();
MeshFilter groundWeaponMesh = groundWeaponObject.GetComponent<MeshFilter>();
BoxCollider groundGunCollider = groundWeaponObject.GetComponent<BoxCollider>();
MeshRenderer groundGunMeshRender = groundWeaponObject.GetComponent<MeshRenderer>();
currentGunController.bullet = groundGunController.bullet;
currentGunController.bulletSpeed = groundGunController.bulletSpeed;
currentGunController.currentAmmo = groundGunController.maxAmmo;
currentGunController.maxAmmo = groundGunController.maxAmmo;
currentGunMesh.sharedMesh = groundWeaponMesh.sharedMesh;
currentGunCollider.size = groundGunCollider.size;
currentGunMeshRender = groundGunMeshRender;
}
}
}
private void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
isTriggered = true;
}
}
private void OnTriggerExit(Collider other) {
if (other.tag == "Player") {
isTriggered = false;
}
}
}
Comment