I want to track a variable in my class that was created outside the scope. In C++ i'd just pass a pointer like this.
class Camera
{
Player* player;
Position pos;
void setFollow(Player* pl) { pl = player; }
void update() { pos = pl->getPos(); }
}
int Main()
{
Camera* camera = new Camera();
Player* player = new Player();
camera->setFollow(player);
}
In C# I tried to pass by reference but it didnt seem to work.
public class Game1 : Microsoft.Xna.Framework.Game
{
Camera cam = new Camera();
Player player = new Player();
cam.setFollow(ref player); // <-- by reference
}
This is just a shortened version of my actual code.
Thanks for any help.
EDIT: Thanks to all for the information.