Moon

Tuple Example

//Custom structure for Sample 3. //Can also be converted to a class if more flexibility is required public struct PlayerInfo { public string playerName; public int playerScore; } public class Tuples : MonoBehaviour { [SerializeField] string athleteName; [SerializeField] int athleteScore; private void Start() { //Sample 1. (string name1, int score1) = GetPlayerInfo(); Debug.Log($"Player: {name1}, Score …

Struct Example

[System.Serializable] public struct Car { public string model; public int speed; //Constructor to initialize the struct public Car(string vehicleName, int vehicleSpeed) { model = vehicleName; speed = vehicleSpeed; } //Method to display vehicle information public void DisplayVehicleDetails() { Debug.Log($"Model: {model}, Speed: {speed}"); } } public class StructListSample : MonoBehaviour { //List to store instance of …

CircleLineRenderer.cs

using UnityEngine; [RequireComponent(typeof(LineRenderer))] public class CircleLineRenderer : MonoBehaviour { private const float DOTTED_LINE_TICKNESS_RATIO = 2.5f; private const int NUM_CAP_VERTICES = 6; [Tooltip("The radius of the circle perimeter")] public float radius = 2; [Tooltip("The width of the line for the circle perimeter")] public float lineWidth = 0.05f; [Tooltip("Check this to use the dotted line material for …

CircularMovement.cs

using UnityEngine; public enum CircularDirection { Clockwise, CounterClockwise } public class CircularMovement : MonoBehaviour { [SerializeField] private GameObject objectToMove; [SerializeField] private bool reverseHalfway = false; [SerializeField] CircularDirection circularDirection = CircularDirection.Clockwise; [SerializeField, Range(0f, 20f)] private float startPosition = 0; [SerializeField, Range(0f, 50f)] private float angularSpeed = 1; [SerializeField, Range(0f, 50f)] private float rotationRadius = 20; //Internal …

SnakeMovement

using System.Collections; using System.Collections.Generic; using UnityEngine; public class SnakeMovement : MonoBehaviour { [Header("Child Objects")] [SerializeField] private List<Transform> _bodyParts = new List<Transform>(); [SerializeField] private float _minDistance = .25f; [SerializeField] private float _speed = 2f; [SerializeField] private float _bodyPartSpacing = 5f; //Interal vars private float _distance; private Transform _currBodyPart; private Transform _prevBodyPart; private Rigidbody2D _firstBodyPart; private bool …

WaveMovement

using System.Collections; using System.Collections.Generic; using UnityEngine; public enum WaveMovementDirection { horizontal, vertical } public class WaveMovement : MonoBehaviour { [SerializeField] private bool playOnStart = false; [SerializeField] private bool disableEventCall = false; [Header("Wave Settings")] [SerializeField] private Transform _parentTransform; [SerializeField] private WaveMovementDirection waveDirection; [SerializeField] private float maxWave = 10f; [Header("Movement Settings")] [SerializeField] private bool moveObject = false; …

Occlusion Manager script

using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.Rendering.Universal; public class OcclusionManager : MonoBehaviour { [SerializeField] private bool occludeLights = true; [SerializeField] private List<Light2D> lights = new(); private Transform _transform; private void Awake() { _transform = transform; //Get lights if(occludeLights) lights = FindObjectsOfType<Light2D>().Select(a => a.GetComponent<Light2D>()).ToList(); } void Update() { if (occludeLights) { foreach (Light2D light in …

Cache Vectors

private Vector3 _myPos; private Transform _transform; private void Awake() { _transform = transform; } private void Update() { _myPos.Set(10, 10, 0); _transform.position = _myPos; }

Coroutine Caching

private WaitForSeconds _waitTime; private void Start() { _waitTime = new WaitForSeconds(1f); } private IEnumerator MyCoroutine() { yield return _waitTime; }

Transform caching

private Transform _transform; private void Awake() { _transform = transform; }

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.

Accept Decline