Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

FREE! Scene draw script

Discussion in 'Assets and Asset Store' started by bgivenb, Jan 27, 2011.

  1. bgivenb

    bgivenb

    Joined:
    Sep 15, 2010
    Posts:
    449
    Hi, I wrote a JavaScript where if the player gets a certain distance from an object, that object changes into something else (a lowpoly version or even an empty object). I use use triggers, and If the player enters the trigger it changes to a high poly version, and vice versa.



    You need both the highpoly.js

    Code (csharp):
    1. //To use: attach this code to your an empty object, and make your high poly prefab a child of your game object. Next, add a box collider to your game object and make the collider a trigger(make sure that it is consideribly larger than your high-poly prefab). Do the same with your low-poly object, use lowpoly.js instread. Give both empty game objects names, and assign eachother as "object" in the editor (make sure both are prefabs). To use, add your lowpoly containing prefab to the scene and enjoy (lowpoly will be changed to high poly if you are within the specified range). If you use, be sure to give credit to Given Borthwick
    2.  
    3.  
    4. var object : Transform;
    5.  
    6.  
    7. function OnTriggerExit(  otherObject3: Collider        ){
    8.  
    9. if(otherObject3.gameObject.tag == "Player"){
    10.     Destroy(gameObject);
    11.  
    12. if (object)
    13.         Instantiate (object, transform.position, transform.rotation);
    14.  
    15. }
    16. }
    17.  
    and lowpoly.js

    Code (csharp):
    1. //instructions on other script
    2.  
    3. var object : Transform;
    4.  
    5.  
    6. function OnTriggerEnter(  otherObject3: Collider        ){
    7.  
    8. if(otherObject3.gameObject.tag == "Player"){
    9.     Destroy(gameObject);
    10.  
    11. if (object)
    12.         Instantiate (object, transform.position, transform.rotation);
    13. }
    14. }

    Webplayer:
    http://dl.dropbox.com/u/11957743/Test.html
    Unity package:
    http://www.filefront.com/17855654/Highpoly-lowpoly.unitypackage
     
  2. RoyS

    RoyS

    Joined:
    Jan 12, 2009
    Posts:
    656
    I can think of some good uses for this. Thank you.
     
  3. Disati

    Disati

    Joined:
    Oct 5, 2009
    Posts:
    111
    Thank you so much. This will be very handy one day.
     
  4. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,884
    Very good work, thanks!
     
  5. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Neat, now I can be lazy and not write my own... But I probably will at some point.

    Thanks :D.
     
  6. bgivenb

    bgivenb

    Joined:
    Sep 15, 2010
    Posts:
    449
    Lol, I started out with a much more complex method, and then after some suggestions from the forum, I almost facepalmed myself, and quickly simplified the code.
     
  7. Caliber-Mengsk

    Caliber-Mengsk

    Joined:
    Mar 24, 2010
    Posts:
    687
    You know what would make this soooooo much better, is modifying the alpha of the material, so it fades in and out rather then just jumping in. I'm not sure how easy or hard that would be to do though.
     
  8. sheva

    sheva

    Joined:
    Nov 22, 2010
    Posts:
    157
    Very very useful :) i like it !!!!
     
  9. chri3topher

    chri3topher

    Joined:
    Jan 31, 2011
    Posts:
    7
    Very NICE!!!!
     
unityunity