I need to instantiate a projectile that is attached to the player's current equipment, the equipment is a GameObject child of the player, so I can't use the Command call by the equipment, I'm doing it in the class responsible for the attack, I tried some ways and I'm not getting. I'm leaving a part of the code the way I expect it to happen and now it asks to serialize the GameObject, I read the documentation about serialization and I didn't understand very well and how I'm going to use it, who can help I really appreciate it.
` protected virtual void RangedAttack()
{
Equipment equipment = _unitEquipment.equipment;
if (isLocalPlayer && RangedEquipment.Instance.GetType().IsInstanceOfType(equipment) && _moviment.TargetManager != null)
{
RangedEquipment rangedEquipment = (RangedEquipment)equipment;
Transform origin = GetComponent<NetworkTransformChild>().target.transform.GetChild(0).GetChild(0);
Transform targetTransform = _moviment.TargetManager.transform;
uint targetId = _moviment.TargetManager.GetComponent<NetworkIdentity>().netId;
float damage = rangedEquipment.Strenght + _attributes.Strenght;
CmdInst(rangedEquipment.Bullet.gameObject, origin, targetTransform, targetId, damage);
}
}
[Command]
void CmdInst(GameObject bullet, Transform origin, Transform targetTransform, uint targetID, float damage)
{
GameObject bulletObject = Instantiate(bullet, origin.position, origin.rotation);
Bullet bulletScript = bulletObject.GetComponent<Bullet>();
bulletScript.TargetPosition = targetTransform;
bulletScript.TargetId = targetID;
bulletScript.Damage = damage;
NetworkServer.Spawn(bulletObject);
}`