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. Dismiss Notice

Can you help me:( Sorry for my bad english:(

Discussion in 'Editor & General Support' started by SpikeSpigel, May 12, 2014.

  1. SpikeSpigel

    SpikeSpigel

    Joined:
    May 12, 2014
    Posts:
    3
    I'm creating a gamne. This game is hardocre survival. Can you give me a youtube link or a tutorial how can i add spawn loot random on map or how can i add cars?
     
  2. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    The script for spawning stuff would be pretty easy:


    Code (csharp):
    1.  
    2. public float minX = 0;
    3. public float minZ = 0;
    4. public float maxX = 50;
    5. public float maxZ = 50;
    6. public GameObject loot;
    7.  
    8. void Start() {
    9. Spawn();
    10. }
    11.  
    12. void Spawn() {
    13.  
    14. float x = Random.range(minX, maxX);
    15. float Z = Random.range(minZ, maxZ);
    16. loot =  Instantiate(loot, new Vector3(x,0,z), Quaternion.identity) as GameObject;
    17.  
    18. }
    19.  
    20.  
    I wrote this on my phone so please re write it in monodevelop to make sure there is no missspellings
     
  3. wildikon

    wildikon

    Joined:
    May 12, 2014
    Posts:
    3
    hi, here's a javascript version

    Code (csharp):
    1. var car : GameObject;//this is a car prefab - (drag from prefabs to this script variable in the inspector...)
    2. var numCars:int=20;    
    3.  
    4. function Start ()//this code doesn't have to go in the Start function... but can be added to any button you like, or event...
    5. {
    6.     for (var i=0; i<numCars; i++)
    7.     {
    8.             float x = Random.range(0, 500);
    9.             float z = Random.range(0, 500);//these two line make random values for x and z to scatter the cars added to the scene
    10.                                                                //y=0 as you probably don't want cars hanging in mid air? but hey, maybe you do!
    11.      
    12.             Instantiate(car ,new Vector3(x,0,z), Quaternion.identity);
    13.     }
    14. }
    hope this helps!

    wildIkon
     
  4. SpikeSpigel

    SpikeSpigel

    Joined:
    May 12, 2014
    Posts:
    3
    Ok, and loot is spawned anywhere on map? Or in house and where i choose? And where i'm need to put this? In terrain?
     
  5. SpikeSpigel

    SpikeSpigel

    Joined:
    May 12, 2014
    Posts:
    3
    I try your script and when i press play a received a error: All compllier or something
     
  6. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    I recommend go watching a few videos on unity before making a game
     
  7. Mukabr

    Mukabr

    Joined:
    Jun 10, 2013
    Posts:
    61
    You should really study a bit more before starting making a complicated project.

    Check this link for more information about scripting, building a project and much more:
    http://unity3d.com/learn/tutorials/modules