Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Spawn and track location of image

Discussion in 'Scripting' started by Serellyn, Mar 13, 2014.

  1. Serellyn

    Serellyn

    Joined:
    Sep 30, 2011
    Posts:
    104
    Hey everyone,

    I've been looking into spawning and moving an image, but I cannot seem to get it to work properly. I will describe step by step what I want, and what the current problem is.

    1. Spawn image on top of screen
    2. Let the image slide down the screen
    3. Check if image is below the bottom of screen
    4. Go to step 1

    So yeah, step 1, spawning the image is pretty simple. But I'm not sure if this is the way I want it because I want to be able to keep track of the location of the image?
    Code (csharp):
    1. GUI.DrawTexture (new Rect(0, locationY, 100, 107), image);
    Step 2, sliding down the screen...
    Code (csharp):
    1. locationY += 2;
    Step 3, now here's the problem. I can not seem to figure out how to track the location of an image... Can anyone think of a solution?

    Edit: I forgot to mention that it should support multiple images at some point. So there might be 82 images on the same time, or there might be only 2 of them. But I do not want to hardcode that ofcourse, so I can't do something like locationY_1, locationY_2 etc... So what would be the best solution?
     
    Last edited: Mar 13, 2014
  2. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    What do you mean by 'track'?
    The position of the image is (0, locationY). What else is there to know?
     
  3. Serellyn

    Serellyn

    Joined:
    Sep 30, 2011
    Posts:
    104
    Sorry I forgot to add something. I'll edit my opening post.
    The thing is that after some time it should be possible to add another picture, and another and another which do the same. So I might have 10 pictures at the same time sliding down the screen, how do I then keep track of them? I do not want static values because I might get 2 images or I might get 83 images on the screen.
     
  4. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Just spawn a new gameobject with your script attached.
    If you want to do it in one script, create a list with one entry for every image.