Category: Programming

  • Optionals in Swift 3

    Swift Optionals A type the either has a “wrapped” value or is nil. e.g. let imagePaths = [“star”: “/glyphs/star.png”,”portrait”: “/images/content/portrait.jpg”,”spacer”: “/images/shared/spacer.gif”] Getting a dictionary’s value using a key returns an optional value, so imagePaths[“star”] has the type String? e.g. if let imagePath = imagePaths[“star”] { print(“The star image is at ‘(imagePath)'”) } else { print(“Couldn’t…

  • Convert numbers to and from strings in Swift

    Convert numbers to and from strings in Swift // To convert a number to a string var costString = String(9.99) // To convert a string to an Int var wholeNumber = Int(“27”) // To convert a string to an Float let lessPrecisePI = Float(“3.14”) // To convert a string to an Double let morePrecisePI =…

  • Automatic Android Code Signing in Unity

    Create a new folder in your project called Editor Within that folder create a new C# script called something like PreloadSigningAlias.cs Copy and paste the code below into the script and save it. Replace KEYSTORE_PASS with the password to your keystore Replace ALIAS_NAME with the name of your android alias Replace ALIAS_PASSWORD with the password…

  • How to solve the “type or namespace UnityEngine.UI does not exist” in Unity

    How to solve the “type or namespace UnityEngine.UI does not exist” in Unity From the Asset menu choose Reimport All That worked for me.

  • Working with Negative Numbers in C#

    To convert a negative number to a positive number, use the Abs function. Like this. int myInt = System.Math.Abs(-5); To convert a positive number to a negative number there is no built in function, but you can simply do this, myInt = myInt * -1

  • Playing A Sound in Unity

    Here’s a simple way to play a sound in Unity. 1. Add something like this to the declaration section of your script. public AudioSource audioSourceExplosion; 2. Add this line of code where you want to play the sound. audioSourceExplosion.Play(); 3. NOTE : What I have called audioSourceExplosion here is the name of the variable and of…

  • Changing C# template for Unity

    The template files for Unity’s scripts are kept in Program FilesUnityEditorDataResourcesScriptTemplates The new behaviour script, the most common one is called (or something similar, depending on version) 81-C# Script-NewBehaviourScript.cs.txt

  • Getting a button to change a text object in Unity 3D

    Using a button to change the text of a text object   1. Insert a Text object using Create -> UI -> Text 2. Insert a Button, using Create -> UI -> Button 3. Create a new script, using Create -> C# Script 4. At the top of the script,  add another using statement, using UnityEngine.UI; at the…

  • Create a new file share with PowerShell

    New-SmbShare –Name fso –Path c:\fso Thanks, Malcolm.

  • How to find a WindowsFeature to install in Powershell

    get-windowsfeature | where {$_.Name -like “*AD*”}