Entertainment, Game Development.

Useful Unity Things to Remember

Here are things that I would normally forget as I do not use them often.

[MenuItem(“KZ/What we doing)] static void WeDoingThis()
{
Debug.Log(“We Did it!”);
}

When you want to exclude only part of a script you can enclose it in compiler flags.

// Runtime code here
#if UNITY_EDITOR
// Editor specific code here
#endif
// Runtime code here

Your ClearPlayerPrefs class should inherit from ScriptableObject since it shouldn’t be attached to objects.

What is the difference between:

[ExecuteInEditMode]

and

#if UNITY_EDITOR
#endif

Answer thanks to echologin:

one lets script run when not in play mode {executeineditmode} and other

only compiles the code in editor not app

anything with a #if is a pre-processor thing so it does that b4 its compiled

public PREFABS thePrefabs;

[System.Serializable]

public class PREFABS

{

public GameObject Something;

}

Now they can be expanded ^

email sending

<pre>
using UnityEngine;
using System.Collections;
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

public class mono_gmail : MonoBehaviour {

void Main ()
{
MailMessage mail = new MailMessage();

mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";

SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "yourpassword") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
Debug.Log("success");

}
}
</pre>

// string comparisons are slow, avoid them. Else use myStringVar.Equals(“word”)

// enum values can be compared by enumType.ValueName

Recently I had to create a new Editor like script and Alverik helped me figure out the missing piece…

var manager = GameObject.FindObjectOfType<SimpleSpawner>();

if (manager == null) return;

Because it will not be used in Build this GameObject.FindObjectOfType is critical to be used to make life easier…

SDK & JDK Locations

C:/Users/UserName/AppData/Local/Android/sdk

C:\Program Files\Java\jdk1.8.0_71\

SDK manager C:\Users\UserName\AppData\Local\Android\sdk

Linear VS Gamma rendering mode color space, in Unity Player Settings it is important to chose between Linear/Gamma and they both are rather different.

In simple terms, if you are targeting PCs and other high end devices (latest consoles and mobile hardwares), go with Lienar as it looks better.

If you want to target all mobiles and other older devices, stick with Gamma all the way through. Important to change this in the beginning of the project, as changing it mid way you may have to tweak colors, materials and more to get it looking OK again.

private public var

public class Variables
{
private static Quaternion spawnLocation;

public static Quaternion SpawnLocation
{
get { return spawnLocation; }
set { spawnLocation = value; }

}
}

you could do timerInSeconds -= Time.unscaledDeltaTime;
and then if (timerInSeconds <= 0) { //Do something }

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: