Hey,I have a DLL that I use to save the player’s position, but when passing the parameters I can only pass Floats created by me, but I want to pass the entire GameObject to the DLL.
This is my code in the DLL;
using System;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace SaveXML
{
public class MyXML
{
public void Save(float lx, float ly, float lz)
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode rootNode;
string filename = "MiPrimerXML.xml";
if (System.IO.File.Exists(filename))
{
xmlDoc.Load(filename);
rootNode = xmlDoc.SelectSingleNode("Game");
}
else
{
rootNode = xmlDoc.CreateElement("Game");
xmlDoc.AppendChild(rootNode);
}
XmlNode userNode = xmlDoc.CreateElement("GameObject");
XmlAttribute attribute = xmlDoc.CreateAttribute("name");
attribute.Value = "Player";
userNode.Attributes.Append(attribute);
rootNode.AppendChild(userNode);
XmlNode Vector = xmlDoc.CreateElement("Vector");
XmlAttribute x = xmlDoc.CreateAttribute("X");
x.Value = lx.ToString();
XmlAttribute y = xmlDoc.CreateAttribute("Y");
y.Value = ly.ToString();
XmlAttribute z = xmlDoc.CreateAttribute("Z");
z.Value = lz.ToString();
Vector.Attributes.Append(x);
Vector.Attributes.Append(y);
Vector.Attributes.Append(z);
userNode.AppendChild(Vector);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new UTF8Encoding(false); // Falso = no escribir BOM
settings.Indent = true;
XmlWriter writer = XmlTextWriter.Create(filename, settings);
xmlDoc.Save(writer);
}
}
}
And this is my code in Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SaveXML;
public class Save : MonoBehaviour
{
private SaveXML.MyXML savedll;
private GameObject Jugador;
// Start is called before the first frame update
void Start()
{
savedll = new MyXML();
Jugador = GameObject.FindGameObjectWithTag("Player");
}
// Update is called once per frame
public void SaveXML()
{
float x = Jugador.transform.position.x;
float y = Jugador.transform.position.y;
float z = Jugador.transform.position.z;
savedll.Save(x, y, z);
}
}