This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unity C# Cheat Sheet | |
// I made these examples for students with prior exerience working with C# and Unity. | |
// Too much? Try Unity's very good tutorials to get up to speed: https://unity3d.com/learn/tutorials/topics/scripting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Primes | |
{ | |
public static IEnumerable<int> SieveOfEratosthenes(int upperLimit) | |
{ | |
int sieveBound = (upperLimit - 1) / 2, | |
upperSqrt = ((int)Math.Sqrt(upperLimit) - 1) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Program | |
{ | |
public static void Main() | |
{ | |
var n = 53; | |
var prime = SieveOfEratosthenes(n); | |
for (int i = 2; i <= n; i++) | |
{ | |
if(prime[i] == 0) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ExploderForceRange : MonoBehaviour | |
{ | |
public float radius = 5f; | |
public float force = 70f; | |
private void OnTriggerEnter(Collider other) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using TMPro; | |
public class CountDown : MonoBehaviour | |
{ | |
public float InstantiationTimer = 2f; | |
public float interval = 2f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class DeerScript : MonoBehaviour | |
{ | |
// this is gameobject whose material will be changed | |
public GameObject target; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class MapGenerator : MonoBehaviour | |
{ | |
public GameObject objectToGenerated; | |
public float theta; | |
public float radius; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
[CustomEditor(typeof(MapGenerator))] | |
public class Edit : Editor | |
{ | |
public override void OnInspectorGUI() | |
{ | |
base.OnInspectorGUI(); | |
MapGenerator mapGenerator = (MapGenerator)target; | |
mapGenerator.Function(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using UnityEngine; | |
using static TMPro.SpriteAssetUtilities.TexturePacker_JsonArray; | |
public class ShapesData | |
{ | |
public float circleRadius; | |
public Vector2 rectangle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MapGenerator is class on which this custom editor will be called | |
using UnityEditor; | |
[CustomEditor(typeof(MapGenerator))] | |
public class Edit : Editor | |
{ | |
public override void OnInspectorGUI() | |
{ | |
base.OnInspectorGUI(); | |
// if you remove |^|(base.OnInspectorGUI(); ) | |
// variable in inspector may not show up properly |
OlderNewer