- Home /
How to save player movement path as a picture?
Answer by Tsaras · Apr 15, 2019 at 06:16 AM
Could use a Linerenderer, although there might be better solutions that I am unaware of.
Answer by m0mohy92 · Apr 15, 2019 at 06:25 AM
I don't want the path to be drawn while playing, i need the collectibles appear in that path, then the path the player moved is saved in a picture.
Answer by toddisarockstar · Apr 15, 2019 at 08:00 AM
here you go.. attach this to the character and save the image when you are done.
public int imagewidth;
public int imageheight;
public int worldtop;
public int worldbottom;
public int worldright;
public int worldleft;
public float xratio,yratio,x,y;
public Texture2D image;
public int pixx,pixy;
void Start () {
int x, y;
worldtop = 500;
worldbottom = -500;
worldright = 500;
worldleft = -500;
imagewidth = 600;
imageheight = 600;
xratio = imagewidth/(float)(worldtop - worldbottom);
yratio = imageheight/(float)(worldright - worldleft);
image = new Texture2D (imagewidth, imageheight);
x = imagewidth;
while(x>0){x--;y = imageheight;
while(y>0){y--;image.SetPixel(x,y,Color.black);}
}image.Apply ();
}
void Update () {
x = transform.position.x;
//use transform position z below if you are 3d;
y = transform.position.y;
pixx = (int)((x - worldleft) *xratio);
pixy = (int)((y - worldbottom)*yratio);
image.SetPixel (pixx, pixy, Color.white);
image.Apply ();
}
void OnGUI(){
GUI.DrawTexture (new Rect (0, 0, 300, 300), image);
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a bubble level (not a game but work tool) 1 Answer
How to trace the movement of player animation? 0 Answers
Stuttering/jerky movement of kinematic rigidbody 2d moving by velocity in 2D game on iOS 0 Answers
NullRefenceException Using Arrays 2 Answers