Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411616 Posts in 69390 Topics- by 58447 Members - Latest Member: sinsofsven

May 10, 2024, 06:51:43 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsUnity3D Scripts, hints and tips
Pages: [1]
Print
Author Topic: Unity3D Scripts, hints and tips  (Read 5381 times)
PlayMeTape
Guest
« on: November 02, 2010, 03:42:58 PM »

Hey Tigfolks! I thought we could start a thread to share some of our scripts, hints and tips for using Unity. Share some of your useful scripts or ask a question you need answered, here's the place!

Here's a simple script for creating a Singleton. If you place this on a GameObject you can make sure it isn't destroyed when you load a new scene. Some good uses can be to keep track of progress, highscore or play audio.

Code:
using UnityEngine;
using System.Collections;

public class Singleton : MonoBehaviour
{
     public static Singleton singleton;

     void Start()
     {
          if (Singleton.singleton == null)
          {
               Singleton.singleton = this;
               DontDestroyOnLoad(gameObject);
          }
          else if (Singleton.singleton != this)
          {
               Destroy(gameObject);
          }
     }
}

Hope people find this useful!
Logged
deathtotheweird
Guest
« Reply #1 on: November 02, 2010, 04:25:54 PM »

Great thread idea, I'll certainly participate. You should also mention what language your scripts are in, since a lot of people use UnityScript (unity's implementation of javascript) instead of C#.

Here's a little tip to fix the blurry 3D text, it's something I see a lot of people never fix. Import the font you want to use, click on it in the Project tab and under the font importer-increase the font size to something like 50. Then select the 3D Text in the Hierarchy and change the character size to your desired size (use .1 to start and increase or decrease)

before and after:


and here is a script (javascript) that will make anything with a mesh filter wireframed:
http://pastie.org/1268233
it's what increpare used for via dolorosa and I used for my entry to the AGBIC compo

not recommended for anything really complex or with a lot of edges, but it works well for simple models with few faces.

Logged
Zaknafein
Level 4
****



View Profile WWW
« Reply #2 on: November 02, 2010, 04:54:11 PM »

I remember reading that you can only use the GL object in Unity Pro, so this text script won't work with the free version. Sad
Cool stuff nonetheless.
Logged

deathtotheweird
Guest
« Reply #3 on: November 02, 2010, 05:13:43 PM »

I know the scripting reference says it's only available in pro, but it works just fine in Unity free. Perhaps some kind of oversight on their part?
Logged
WafflePilot
Level 0
**


View Profile WWW
« Reply #4 on: November 02, 2010, 05:16:37 PM »

Hey Tigfolks! I thought we could start a thread to share some of our scripts, hints and tips for using Unity. Share some of your useful scripts or ask a question you need answered, here's the place!

Here's a simple script for creating a Singleton. If you place this on a GameObject you can make sure it isn't destroyed when you load a new scene. Some good uses can be to keep track of progress, highscore or play audio.

Code:
using UnityEngine;
using System.Collections;

public class Singleton : MonoBehaviour
{
     public static Singleton singleton;

     void Start()
     {
          if (Singleton.singleton == null)
          {
               Singleton.singleton = this;
               DontDestroyOnLoad(gameObject);
          }
          else if (Singleton.singleton != this)
          {
               Destroy(gameObject);
          }
     }
}

Hope people find this useful!



Nice i had no idea gameObjects can persist between scenes! I've been writing and reading so much xml between scenes it's been getting crazy .. thanks
Logged
radioact1ve
Level 0
**


What?


View Profile WWW
« Reply #5 on: November 02, 2010, 08:00:09 PM »

I know the scripting reference says it's only available in pro, but it works just fine in Unity free. Perhaps some kind of oversight on their part?

Just wondering here, are you using free edition that comes with Pro trial? Did it expire already?
Logged

deathtotheweird
Guest
« Reply #6 on: November 02, 2010, 08:16:36 PM »

No I use pro. when you make games with the pro trial it says "trial version" in the lower right hand corner. then after 30 days it reverts to unity free. So if you're worried about the pro trial screwing up the free part, it won't. It'll just simply change back to unity free after the trial is over.
Logged
Matthew
Rapture
Administrator
Level 3
******


Milling About


View Profile WWW
« Reply #7 on: November 02, 2010, 09:29:16 PM »

For JavaScript singletons, you probably want to use Awake(), which is fired before Start() -- this way other scripts can use the singleton in their own Start() functions.  For C# you can use properties to find the singleton on demand.  Here's a good template:

http://www.unifycommunity.com/wiki/index.php?title=AManagerClass
Logged

Matthew Wegner
Currently: Aztez
Founder, Flashbang Studios
Partner, Indie Fund
Editor, Fun-Motion
Co-Chair, IGF
deathtotheweird
Guest
« Reply #8 on: November 05, 2010, 06:09:18 PM »

I just came across this nice visual editor for iTween (very helpful animation library)

http://dkoontz.wordpress.com/2010/10/27/itween-visual-editor/

Makes doing simple animations much easier, I haven't used it yet but I can definitely see the value in it for speeding things up.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic